Pthread Barrier vs. Loop Join
Asked Answered
B

1

7

So my question in C is: what is basically the differences (maybe pros and cons) of using a pthread barrier (init and wait..etc) compared to using the pthread Join in a loop.

So say I created 10 threads in a loop, and then later at the place of where I want a barrier, I put a loop to do Join for all the threads. Wouldn't that act as a Barrier too?

Please clarify. Thanks!

Brakeman answered 6/12, 2010 at 4:33 Comment(0)
E
4

pthread_join() blocks the calling thread until the joining thread exits. In contrast, a barrier allows the all threads to continue running.

Elephantine answered 6/12, 2010 at 4:43 Comment(2)
I do not understand, sorry for that. If you have a program like here: Multithreading in C++ article from geekforgeeks (cannot insert link) we can see that a std::join (NOT pthread_join()) if there for main not to terminate before the threads are running. However, the sequential order of joins does not give you the execution order. So, if I would use a barrier instead, I have the same PROCEDURE. Can you please clarify the difference maybe with an example? Thank youAllowance
@user3742309: This was answering the specific question about the difference between doing a pthread_join in a loop and using a barrier blocking the same set of threads instead. As the answer says, if you use a barrier then you can have the 'target' threads continue executing after they have synchronised with the main thread at the barrier. It sounds like your question might be substantially different to this one, so maybe ask it as a new question.Elephantine

© 2022 - 2024 — McMap. All rights reserved.