package index

  1. Overview
  2. Docs

Locks for mutual exclusion

type t

The type of mutual-exclusion locks.

val create : unit -> t

Return a fresh mutex.

val lock : t -> unit

Lock the given mutex. Locks are not assumed to be re-entrant.

val unlock : t -> unit

Unlock the mutex. If any threads are attempting to lock the mutex, exactly one of them will gain access to the lock.

val with_lock : t -> (unit -> 'a) -> 'a

with_lock t f first obtains t, then computes f (), and finally unlocks t.