Locks can be used to control access to shared data by several processes.
A lock has the following components:
name
(a string),
lock
(
t
or
nil
, that is, whether the lock is set or not),
owner
(a process, or
nil
) and
count
(an integer showing the number of times the lock has been set).
The two main symbols used in locking are the function
make-lock
, to create a lock, and the macro
with-lock
, 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
important-p
is
t
the lock is added to the list held in the global variable
mp:*important-locks*
. The function
mp:free-important-locks
frees all important locks associated with a given process (or all the important locks if called on
nil
). 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
timeout
elapses if it has been specified. Returns
t
if lock was claimed,
nil
otherwise.
mp:process-unlock
lock
&optional
errorp
Releases the lock. If
errorp
is non-
nil
it signals an error if the current process does not own the lock. The default value of
errorp
is
t
.
mp:with-lock ((
lock
&rest
lock-args
) &body
body
Executes the body with lock held. Arguments to pass on to
mp:process-lock
are specified using
lock-args
.
The following accessors are available for locks:
lock-owner
,
lock-count
,
lock-name
and
lock-lock
.