Create a new semaphore with the given initial count $n$.
$$\text{new} : \text{Nat} \to \text{BaseIO}\ \text{QSem}$$
Equations
- Control.Concurrent.QSem.new initial = do let __do_lift ← Std.Mutex.new { count := initial, waiters := ∅ } pure { state := __do_lift }
Instances For
Acquire one unit of the semaphore. If no units are available,
the caller becomes a dormant promise until signal releases one.
$$\text{wait} : \text{QSem} \to \text{BaseIO}\ (\text{Task}\ \text{Unit})$$
Never blocks an OS thread. FIFO fairness.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Release one unit of the semaphore. If there are waiting tasks, the first one in FIFO order is woken.
$$\text{signal} : \text{QSem} \to \text{BaseIO}\ \text{Unit}$$
No-lost-wakeup guarantee: either a waiter is woken or the count is incremented. Both branches are mutually exclusive.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Acquire one unit, run an action, then release — even if the action throws.
Guarantees the semaphore is released via try/finally.
$$\text{withSem} : \text{QSem} \to \text{IO}\ \alpha \to \text{IO}\ \alpha$$