Mutual exclusion primitive (a lock).
If you want to guard shared state, use Mutex α
instead.
Equations
Instances For
Creates a new BaseMutex
.
Locks a BaseMutex
. Waits until no other thread has locked the mutex.
The current thread must not have already locked the mutex. Reentrant locking is undefined behavior (inherited from the C++ implementation).
Unlocks a BaseMutex
.
The current thread must have already locked the mutex. Unlocking an unlocked mutex is undefined behavior (inherited from the C++ implementation).
Condition variable.
Equations
Instances For
Creates a new condition variable.
Wakes up a single other thread executing wait
.
Wakes up all other threads executing wait
.
Waits on the condition variable until the predicate is true.
Equations
- One or more equations did not get rendered due to their size.
Instances For
- ref : IO.Ref α
- mutex : IO.BaseMutex
Mutual exclusion primitive (lock) guarding shared state of type α
.
The type Mutex α
is similar to IO.Ref α
,
except that concurrent accesses are guarded by a mutex
instead of atomic pointer operations and busy-waiting.
Instances For
Equations
- IO.instCoeOutMutexBaseMutex = { coe := IO.Mutex.mutex }
Creates a new mutex.
Equations
- IO.Mutex.new a = do let __do_lift ← IO.mkRef a let __do_lift_1 ← IO.BaseMutex.new pure { ref := __do_lift, mutex := __do_lift_1 }
Instances For
mutex.atomically k
runs k
with access to the mutex's state while locking the mutex.
Equations
- IO.Mutex.atomically mutex k = tryFinally (do liftM (IO.BaseMutex.lock mutex.mutex) k mutex.ref) (liftM (IO.BaseMutex.unlock mutex.mutex))
Instances For
mutex.atomicallyOnce condvar pred k
runs k
,
waiting on condvar
until pred
returns true.
Both k
and pred
have access to the mutex's state.
Equations
- IO.Mutex.atomicallyOnce mutex condvar pred k = let x := { monadLift := fun {α} => liftM }; IO.Mutex.atomically mutex do IO.Condvar.waitUntil condvar mutex.mutex pred k