fix(thread_pool): notify under the mutex in post#372
Conversation
join() guarantees the work has drained, not that foreign posting threads have left post(). A cross-executor completion could enqueue its item, have it consumed, and see the pool join and destruct while the poster was still inside the condition variable signal (pthread_cond_signal racing pthread_cond_destroy, TSan-confirmed). Notifying while holding the mutex orders the destroy after the poster's last touch of the condition variable: the consumer cannot pop until the poster releases the lock. Wait morphing keeps the held-lock notify cheap on Linux. The regression test hops a task through a long-lived worker pool back into a short-lived pool that joins and dies immediately; under TSan the race reproduced on every run before the fix.
|
An automated preview of the documentation is available at https://372.capy.prtest3.cppalliance.org/index.html If more commits are pushed to the pull request, the docs will rebuild at the same URL. 2026-07-23 16:07:10 UTC |
|
GCOVR code coverage report https://372.capy.prtest3.cppalliance.org/gcovr/index.html Build time: 2026-07-23 16:20:23 UTC |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #372 +/- ##
===========================================
+ Coverage 98.18% 98.33% +0.15%
===========================================
Files 152 152
Lines 8246 8288 +42
===========================================
+ Hits 8096 8150 +54
+ Misses 150 138 -12
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 5 files with indirect coverage changes Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
join() guarantees the work has drained, not that foreign posting threads have left post(). A cross-executor completion could enqueue its item, have it consumed, and see the pool join and destruct while the poster was still inside the condition variable signal (pthread_cond_signal racing pthread_cond_destroy, TSan-confirmed).
Notifying while holding the mutex orders the destroy after the poster's last touch of the condition variable: the consumer cannot pop until the poster releases the lock. Wait morphing keeps the held-lock notify cheap on Linux.
The regression test hops a task through a long-lived worker pool back into a short-lived pool that joins and dies immediately; under TSan the race reproduced on every run before the fix.