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).
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
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.
- ref : IO.Ref α
- mutex : IO.BaseMutex
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
- mutex.atomically k = tryFinally (do liftM mutex.mutex.lock k mutex.ref) (liftM mutex.mutex.unlock)
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.