fix(libkernel): let pthread_barrier_destroy wait for released waiters #4002
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4002"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by zmeizy on 2026-10-11T21:11:22Z.
What
pthread_barrier_destroyreturnedEBUSYwhile any thread released by the lastpthread_barrier_waithad not yet returned from it. The common pattern where the thread that getsPTHREAD_BARRIER_SERIAL_THREADdestroys the barrier therefore failed almost every time, and the barrier leaked.FreeBSD 11 libthr (
thr_barrier.c,_pthread_barrier_destroy) returnsEBUSYonly while threads are still blocked in the current cycle (b_waiters). It waits for released threads to leave (b_refcount) before it frees the barrier.The barrier now does the same:
destroyreturnsEBUSYonly while threads wait in the current cycle.pthread_barrier_wait.Tested
Ubuntu 24.04, GCC 13.3, on
main0a8b1d32.guest_pthread_barrier: a new check runs 50 rounds of 4 threads in which the serial thread destroys the barrier. Each destroy must return 0 and leave the pointer null.mainwithout the change and passes with it (3 runs).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt (n/a).mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
https://claude.ai/code/session_01Ha6Tsy62AFUyp9a5Mf7vjA