Stdlib.Semaphore(3)

πŸ’… Stdlib.Semaphore β€” no description (welcome to the OCaml library manual, bestie; this is Stdlib.Semaphore(3))

okay so real talk: this page is literally the Stdlib.Semaphore(3) entry in the OCaml library manual, and the NAME section is giving minimal queen energy. no cap.

πŸ’– NAME πŸ’–

  • Stdlib.Semaphore β€” no description

πŸ¦‹ MODULE πŸ¦‹

the module itself is just:

Module Stdlib.Semaphore

✨ DOCUMENTATION ✨

documentation time, bestie. here's the module layout:

Module Semaphore
        : (module Stdlib__Semaphore)

πŸ’… Counting semaphores πŸ’…

A counting semaphore is a counter that can be accessed concurrently by several threads. The typical use is to synchronize producers and consumers of a resource by counting how many units of the resource are available.

The two basic operations on semaphores are, and yes bestie there are literally two:

  • "release" (also called "V", "post", "up", and "signal") β€” increments the value of the counter. This corresponds to producing one more unit of the shared resource and making it available to others.
  • "acquire" (also called "P", "wait", "down", and "pend") β€” waits until the counter is greater than zero and decrements it. This corresponds to consuming one unit of the shared resource.

and the module tucked inside this section is literally: module Counting : sig end

πŸŽ€ Binary semaphores πŸŽ€

Binary semaphores are a variant of counting semaphores where semaphores can only take two values, 0 and 1.

A binary semaphore can be used to control access to a single shared resource, with value 1 meaning "resource is available" and value 0 meaning "resource is unavailable".

The "release" operation of a binary semaphore sets its value to 1, and "acquire" waits until the value is 1 and sets it to 0.

A binary semaphore can be used instead of a mutex (see module Mutex) when the mutex discipline (of unlocking the mutex from the thread that locked it) is too restrictive. The "acquire" operation corresponds to locking the mutex, and the "release" operation to unlocking it, but "release" can be performed in a thread different than the one that performed the "acquire". Likewise, it is safe to release a binary semaphore that is already available.

and the module inside this section is: module Binary : sig end


made with πŸ’– by OCamldoc on 2026-06-22 β€” that's the source/version and date for Stdlib.Semaphore(3), periodt 🫢

πŸ“¦ where this page comes from