11.2.3 Semaphores
A semaphore has an internal counter; when this counter is zero, the semaphore can block a thread’s execution (through semaphore-wait) until another thread increments the counter (using semaphore-post). The maximum value for a semaphore’s internal counter is platform-specific, but always at least 10000.
A semaphore’s counter is updated in a single-threaded manner, so that semaphores can be used for reliable synchronization. Semaphore waiting is fair: if a thread is blocked on a semaphore and the semaphore’s internal value is non-zero infinitely often, then the thread is eventually unblocked.
In addition to its use with semaphore-specific procedures, a semaphore can be used as a synchronizable event (see Events). A semaphore is ready for synchronization when semaphore-wait would not block; the synchronization result of a semaphore is the semaphore itself.
procedure
(semaphore? v) → boolean?
v : any/c
procedure
(make-semaphore [init]) → semaphore?
init : exact-nonnegative-integer? = 0
procedure
(semaphore-post sema) → void?
sema : semaphore?
procedure
(semaphore-wait sema) → void?
sema : semaphore?
procedure
(semaphore-try-wait? sema) → boolean?
sema : semaphore?
procedure
(semaphore-wait/enable-break sema) → void?
sema : semaphore?
procedure
(semaphore-peek-evt sema) → semaphore-peek-evt?
sema : semaphore?
procedure
(semaphore-peek-evt? v) → boolean?
v : any/c
procedure
(call-with-semaphore sema proc [ try-fail-thunk] arg ...) → any sema : semaphore? proc : procedure? try-fail-thunk : (or/c (-> any) #f) = #f arg : any/c
procedure
(call-with-semaphore/enable-break sema proc [ try-fail-thunk] arg ...) → any sema : semaphore? proc : procedure? try-fail-thunk : (or/c (-> any) #f) = #f arg : any/c