Locks can be used to control access to shared data by several processes.
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.
A lock has a name (a string) and several other components. The printed representation of a lock shows the name of the lock and whether it is currently locked. Additionally if the lock is locked it shows the name of the process holding the lock, and how many times that process has locked it. For example:
#<MP:LOCK "my-lock" Locked 2 times by "My Process" 2008CAD8>
returns the process that locked a given lock.
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.
Blocks the current process until the lock is claimed or
elapses if it has been specified. Returns
if lock was claimed,
Releases the lock. If
it signals an error if the current process does not own the lock. The default value of
Executes the body with lock held. Arguments to pass on to
are specified using
The following accessor is available for locks: