Locks can be used to control access to shared data by several processes.
A lock has the following components:
, that is, whether the lock is set or not),
(a process, or
(an integer showing the number of times the lock has been set).
The two main symbols used in locking are the function
, to create a lock, and the macro
, to execute a body of code while holding the specified lock.
mp:make-lock &key important-p &allow-other-keys
Creates a lock object. If
the lock is added to the list held in the global variable
. The function
frees all important locks associated with a given process (or all the important locks if called on
). Other keywords should be names of the lock components.
mp:process-lock lock &optional whostate timeout
Blocks the current process until the lock is claimed or
elapses if it has been specified. Returns
if lock was claimed,
mp:process-unlock lock &optional errorp
Releases the lock. If
it signals an error if the current process does not own the lock. The default value of
mp:with-lock (( lock &rest lock-args ) &body body
Executes the body with lock held. Arguments to pass on to
are specified using
The following accessors are available for locks: