.TH "Semaphore.Counting" 3o 2023-02-12 OCamldoc "OCaml library" .SH NAME Semaphore.Counting \- no description .SH Module Module Semaphore.Counting .SH Documentation .sp Module .BI "Counting" : .B sig end .sp .sp .sp .sp .I type t .sp The type of counting semaphores\&. .sp .I val make : .B int -> t .sp .ft B make n .ft R returns a new counting semaphore, with initial value .ft B n .ft R \&. The initial value .ft B n .ft R must be nonnegative\&. .sp .B "Raises Invalid_argument" if .ft B n < 0 .ft R .sp .I val release : .B t -> unit .sp .ft B release s .ft R increments the value of semaphore .ft B s .ft R \&. If other threads are waiting on .ft B s .ft R , one of them is restarted\&. If the current value of .ft B s .ft R is equal to .ft B max_int .ft R , the value of the semaphore is unchanged and a .ft B Sys_error .ft R exception is raised to signal overflow\&. .sp .B "Raises Sys_error" if the value of the semaphore would overflow .ft B max_int .ft R .sp .I val acquire : .B t -> unit .sp .ft B acquire s .ft R blocks the calling thread until the value of semaphore .ft B s .ft R is not zero, then atomically decrements the value of .ft B s .ft R and returns\&. .sp .I val try_acquire : .B t -> bool .sp .ft B try_acquire s .ft R immediately returns .ft B false .ft R if the value of semaphore .ft B s .ft R is zero\&. Otherwise, the value of .ft B s .ft R is atomically decremented and .ft B try_acquire s .ft R returns .ft B true .ft R \&. .sp .I val get_value : .B t -> int .sp .ft B get_value s .ft R returns the current value of semaphore .ft B s .ft R \&. The current value can be modified at any time by concurrent .ft B Semaphore\&.Counting\&.release .ft R and .ft B Semaphore\&.Counting\&.acquire .ft R operations\&. Hence, the .ft B get_value .ft R operation is racy, and its result should only be used for debugging or informational messages\&. .sp