Query and behavior confirmation for pthread_barrier_destroy(3)

Florian Weimer fweimer@redhat.com
Thu Sep 3 12:04:28 GMT 2020


* Shashank Agarwal:

> Thanks for the confirmation. Please let me know if my understanding is
> correct about pthread_barrier_destroy(3).
>
>> A barrier can be destroyed as soon as no threads are blocked on the
>> barrier.
>
> If yes please let me know how I can verify this behaviour.

“As soon as” is imprecise; the specification predates the C/C++ memory
model.  The caller of pthread_barrier_destroy has to establish a
happens-before relationship with the return from the
pthread_barrier_wait calls on the other threads.

The intent with the current glibc implementation is that the
synchronization can be achieved using the same barrier (if no thread
blocks again on the barrier after the current round of waiting).  That
is, in your test, thread 2 would have to wait on the barrier as well,
unblocking both tests, and then destroy the barrier.

Thanks,
Florian



More information about the Libc-alpha mailing list