pub struct Semaphore { /* private fields */ }Expand description
Counting semaphore built on Mutex + Condvar so blocked acquirers park in
the kernel rather than spinning on an atomic.
Replaces the prior pattern in pipeline::chunked::exec:
ⓘ
while atomic.load(Relaxed) >= max { thread::sleep(50ms); }
atomic.fetch_add(1, Relaxed);which polled 20 times/sec per blocked worker. Under N parallel chunks and a long-running export this burned ~N × 20 wake-ups per second doing nothing.
With Condvar::wait, blocked threads consume zero CPU until a release()
notifies. The mutex is uncontended whenever traffic is light, so the lock
path adds no measurable overhead vs the atomic.
Implementations§
Auto Trait Implementations§
impl !Freeze for Semaphore
impl RefUnwindSafe for Semaphore
impl Send for Semaphore
impl Sync for Semaphore
impl Unpin for Semaphore
impl UnsafeUnpin for Semaphore
impl UnwindSafe for Semaphore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more