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!
POSIX threads specifies a synchronization object called a barrier, along with barrier functions. The functions create the barrier, specifying the number of threads that are synchronizing on the barrier, and set up threads to perform tasks and wait at the barrier until all the threads reach the barrier.
Yes if thread is attachable then pthread_join is must otherwise it creates a Zombie thread. Agree with answers above, just sharing a note from man page of pthread_join. After a successful call to pthread_join(), the caller is guaranteed that the target thread has terminated.
You can certainly call pthread_join() from the running thread itself, and as you have found out the call itself will handle it properly giving you an error code.
pthread_join()
blocks the calling thread until the joining thread exits. In contrast, a barrier allows the all threads to continue running.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With