Locks can be used to control access to shared data by several processes.
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.
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>
The function lock-owner returns the process that locked a given lock.
The function lock-name returns the name of a lock.
The function process-lock blocks the current process until a given lock is claimed or a timeout passes, and process-unlock releases the lock.
The macro with-lock executes code with a lock held, and releases the lock on exit, as if by process-lock and process-unlock.
If you need to avoid blocking on a lock that is held by some other thread, then use with-lock with timeout 0, like this:
(unless (mp:with-lock (lock nil 0)
The macros with-sharing-lock and with-exclusive-lock can be used with sharing locks.
LispWorks User Guide and Reference Manual - 21 Dec 2011