Mutual exclusion primitive (a lock).
If you want to guard shared state, use Mutex α
instead.
Equations
Instances For
@[extern lean_io_basemutex_new]
Creates a new BaseMutex
.
@[extern lean_io_basemutex_lock]
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).
@[extern lean_io_condvar_new]
Creates a new condition variable.
Equations
- Std.instCoeOutMutexBaseMutex = { coe := Std.Mutex.mutex }
Creates a new mutex.
Equations
- Std.Mutex.new a = do let __do_lift ← IO.mkRef a let __do_lift_1 ← Std.BaseMutex.new pure { ref := __do_lift, mutex := __do_lift_1 }
Instances For
def
Std.Mutex.atomically
{m : Type → Type}
{α β : Type}
[Monad m]
[MonadLiftT BaseIO m]
[MonadFinally m]
(mutex : Mutex α)
(k : AtomicT α m β)
:
m β
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 (Std.Mutex.ref✝ mutex)) (liftM mutex.mutex.unlock)
Instances For
def
Std.Mutex.atomicallyOnce
{m : Type → Type}
{α β : Type}
[Monad m]
[MonadLiftT BaseIO m]
[MonadFinally m]
(mutex : Mutex α)
(condvar : Condvar)
(pred : AtomicT α m Bool)
(k : AtomicT α m β)
:
m β
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
- mutex.atomicallyOnce condvar pred k = mutex.atomically do condvar.waitUntil mutex.mutex pred k