Commit graph

3 commits

Author SHA1 Message Date
Antonio S. Musumeci
6a52d7b1a2 Fix semaphore drift from enqueue_unbounded in BoundedQueue
enqueue_unbounded bypasses the semaphore so control messages
(poison pills, thread removal tasks) can never block on a full
queue. But wait_dequeue always signals a slot after consuming,
so each unbounded item that gets dequeued inflated the semaphore
by +1, permanently raising the effective max queue depth.

Fix by calling tryWait() in enqueue_unbounded before enqueueing.
When the queue has room (common case), this consumes a slot and
the dequeue-side signal restores balance perfectly. When the queue
is genuinely full (tryWait fails), the item still enqueues but
temporarily exceeds max_depth by one until consumed - a transient
overshoot bounded by control messages in flight.

A CAS-based approach that absorbed extra signals on the dequeue
side was also considered but rejected: it can starve blocked
bounded producers by swallowing the signal they are waiting for.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 20:21:36 -04:00
Antonio S. Musumeci
9dc461c96d checkpoint 2026-04-09 19:13:58 -04:00
Antonio SJ Musumeci
164b7f73c9 Misc fixes and improvements to thread pool 2026-03-24 21:13:34 -04:00