Documentation

Std.Sync.RecursiveMutex

Recursive (or reentrant) exclusion primitive.

If you want to guard shared state, use RecursiveMutex α instead.

Equations
Instances For
    @[extern lean_io_baserecmutex_new]

    Creates a new BaseRecursiveMutex.

    @[extern lean_io_baserecmutex_lock]

    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.

    @[extern lean_io_baserecmutex_try_lock]

    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.

    @[extern lean_io_baserecmutex_unlock]

    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).

    structure Std.RecursiveMutex (α : Type) :

    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.

    Instances For

      Creates a new recursive mutex.

      Equations
      Instances For
        def Std.RecursiveMutex.atomically {m : TypeType} {α β : Type} [Monad m] [MonadLiftT BaseIO m] [MonadFinally m] (mutex : RecursiveMutex α) (k : AtomicT α m β) :
        m β

        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
        Instances For
          def Std.RecursiveMutex.tryAtomically {m : TypeType} {α β : Type} [Monad m] [MonadLiftT BaseIO m] [MonadFinally m] (mutex : RecursiveMutex α) (k : AtomicT α m β) :
          m (Option β)

          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.
          Instances For