Recursive (or reentrant) exclusion primitive.
If you want to guard shared state, use RecursiveMutex α
instead.
Instances For
Creates a new BaseRecursiveMutex
.
Locks a RecursiveBaseMutex
. Waits until no other thread has locked the mutex.
If the current thread already holds the mutex this function doesn't block.
Attempts to lock a RecursiveBaseMutex
. If the mutex is not available return false
, otherwise
lock it and return true
.
This function does not block. Furthermore the same thread may acquire the lock multiple times through this function.
Unlocks a RecursiveBaseMutex
. The owning thread must make as many unlock
calls as lock
and
tryLock
calls in order to fully relinquish ownership of the mutex.
The current thread must have already locked the mutex at least once. Unlocking an unlocked mutex is undefined behavior (inherited from the C++ implementation).
Recursive (or reentrant) mutual exclusion primitive (lock) guarding shared state of type α
.
The type RecursiveMutex α
is similar to IO.Ref α
, except that concurrent accesses are guarded
by a mutex instead of atomic pointer operations and busy-waiting. Additionally locking a
RecursiveMutex
multiple times from the same thread does not block, unlike Mutex
.
- ref : IO.Ref α
- mutex : BaseRecursiveMutex
Instances For
Equations
Creates a new recursive mutex.
Equations
- Std.RecursiveMutex.new a = do let __do_lift ← IO.mkRef a let __do_lift_1 ← Std.BaseRecursiveMutex.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.
Calling mutex.atomically
while already holding the underlying BaseRecursiveMutex
in the same
thread does not block.
Equations
- mutex.atomically k = tryFinally (do liftM mutex.mutex.lock k (Std.RecursiveMutex.ref✝ mutex)) (liftM mutex.mutex.unlock)
Instances For
mutex.tryAtomically k
tries to lock mutex
and runs k
on it if it succeeds. On success the
return value of k
is returned as some
, on failure none
is returned.
This function does not block on the mutex
. Additionally mutex.tryAtomically
, while already
holding the underlying BaseRecursiveMutex
in the same thread, does not block.
Equations
- One or more equations did not get rendered due to their size.