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.

Raises Invalid_argument if n < 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 😭

Raises Sys_error if the value of the semaphore would overflow max_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