Semaphore.Counting(3)
π NAME π
okay bestie, welcome to Semaphore.Counting(3) from the OCaml library manual β¨ this page is for Semaphore.Counting, and the official description is literally just βno descriptionβ ππ iconic minimalism, honestly.
π§ Module π§
Module Semaphore.Counting
β¨ Documentation β¨
Module Counting : sig end
π type t
this is the type of counting semaphores π«Ά thatβs the whole vibe check for t.
πΈ val make : int -> t
make n returns a new counting semaphore with initial value n β¨ and bestie, that initial n must be nonnegative.
RaisesInvalid_argumentifn < 0π no negative semaphore nonsense allowed.
π¦ val release : t -> unit
release s increments the value of semaphore s π₯ if other threads are waiting on s, one of them gets restarted. but watch out: if the current value of s is equal to max_int, the value of the semaphore stays unchanged and a Sys_error exception is raised to signal overflow π
RaisesSys_errorif the value of the semaphore would overflowmax_int.
π val acquire : t -> unit
acquire s blocks the calling thread until the value of semaphore s is not zero, then atomically decrements the value of s and returns π thatβs the whole locking moment, no cap.
β val try_acquire : t -> bool
try_acquire s immediately returns false if the value of semaphore s is zero π otherwise, the value of s is atomically decremented and try_acquire s returns true β¨ lowkey the βtryβ version fr fr.
π val get_value : t -> int
get_value s returns the current value of semaphore s π but bestie, the current value can be modified at any time by concurrent Semaphore.Counting.release and Semaphore.Counting.acquire operations. hence, the get_value operation is racy, and its result should only be used for debugging or informational messages π so donβt build your whole main character algorithm on it, okay?
mwah π signed off by OCamldoc on 2026-06-22, for the page Semaphore.Counting(3) β periodt π
π«Ά
π¦ where this page comes from
- arch rolling: ocaml 5.5.0-1 Β· LGPL2.1 AND custom: QPL-1.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms