Skip to main content

Module blocking_semaphore

Module blocking_semaphore 

Source
Expand description

BlockingSemaphore: cross-process counting semaphore with a kernel-park slow path via CrossProcessWaker.

Composes crate::shared_semaphore::SharedSemaphore (the counter + generation-counter primitive) with one CrossProcessWaker. The hot path is unchanged from SharedSemaphore::try_acquire: a single CAS on the permit count. The contention slow path differs:

  • SharedSemaphore::acquire loops try_acquireyield_nowsleep(50us) indefinitely. The sleep tail burns CPU on the wake-up tick AND can miss a release by up to 50us.
  • BlockingSemaphore::acquire_park loops try_acquire, then registers in the waker at the current generation, then parks via the platform wait syscall. The kernel returns within microseconds of the next release.

Cross-process Linux uses SHARED futex so a release from process A wakes a parker in process B. Windows runs intra- process via WaitOnAddress (one process at a time, share via Arc::clone).

Structs§

BlockingPermit
RAII guard for an acquired permit. Drops to release.
BlockingSemaphore
Cross-process semaphore with a kernel-park slow path.

Enums§

BlockingSemaphoreError
Errors returned by BlockingSemaphore operations.