Module Lock

module Lock: sig .. end
Reentrant locks.

type t = java'util'concurrent'locks'Lock java_instance
The type of (reentrant) locks.
 
val make_reentrant : ?fair:bool -> unit -> t
Returns a new reentrant lock, the parameter indicates whether a fair ordering policy is requested (defaulting to false); see ReentrantLock(...).
 
val lock : t -> unit
Acquires the lock. Returns immediately if the lock is either not held by another thread, or already held by the current thread. Otherwise, the current thread is blocked until the holding thread releases the lock; see lock(...).
 
val lock_interruptibly : t -> unit
Similar to Lock.lock, except that some other thread may interrupt the current thread while blocked; see lockInterruptibly(...).
Raises Java_exception if the thread is interrupted
 
val new_condition : t -> Condition.t
Returns a new condition associated with the passed lock; see newCondition(...).
 
val try_lock : t -> bool
Acquires the lock if available, returning true. Otherwise, immediately returns false; see tryLock(...).
 
val try_lock_time : t -> java_long -> TimeUnit.t -> bool
try_lock_time l t u is similar to lock_interruptibly l, except that the current thread will at most wait for t (time value whose unit is u). Returns whether the lock was acquired; see tryLock(...).
Raises Java_exception if the thread is interrupted
 
val unlock : t -> unit
Releases the lock; see unlock(...).
Raises Java_exception if the current thread does not hold the lock
 

Null value

 
val null : t
The null value.
 
val is_null : t -> bool
is_null obj returns true iff obj is equal to null.
 
val is_not_null : t -> bool
is_not_null obj returns false iff obj is equal to null.
 

Miscellaneous

 
val wrap : t -> t option
wrap obj wraps the reference obj into an option type:
  • Some x if obj is not null;
  • None if obj is null.

 
val unwrap : t option -> t
unwrap obj unwraps the option obj into a bare reference:
  • Some x is mapped to x;
  • None is mapped to null.