Module Lwt_mutex
Cooperative locks for mutual exclusion
val create : unit -> tcreate ()creates a new mutex, which is initially unlocked
val lock : t -> unit Lwt.tlock mutexlockcs the mutex, that is:- if the mutex is unlocked, then it is marked as locked and
lockreturns immediately
- if it is locked, then
lockwaits for all threads waiting on the mutex to terminate, then it resumes when the last one unlocks the mutex
Note: threads are woken up in the same order they try to lock the mutex
- if the mutex is unlocked, then it is marked as locked and
val unlock : t -> unitunlock mutexunlock the mutex if no threads is waiting on it. Otherwise it will eventually removes the first one and resumes it.
val is_locked : t -> boollocked mutexreturns whethermutexis currently locked
val is_empty : t -> boolis_empty mutexreturnstrueif they are no thread waiting on the mutex, andfalseotherwise
val with_lock : t -> (unit -> 'a Lwt.t) -> 'a Lwt.twith_lock lock fis used to lock a mutex within a block scope. The functionf ()is called with the mutex locked, and its result is returned from the call towith_lock. If an exception is raised from f, the mutex is also unlocked before the scope ofwith_lockis exited.