All Manuals > LispWorks® User Guide and Reference Manual > 42 The MP Package

make-lock Function

Summary

Makes a lock.

Package

mp

Signature

make-lock &key name important-p safep recursivep sharing => lock

Arguments
name
A string.
important-p
A generalized boolean.
safep
A generalized boolean.
recursivep
A generalized boolean.
sharing
A generalized boolean.
Values
lock
A lock.
Description

The function make-lock creates a lock. See 19.4 Locks for a general description of locks.

name names lock and can be queried with lock-name. The default value of name is "Anon".

important-p controls whether lock is automatically freed when the holder process finishes. When important-p is true, the system notes that lock is important, and automatically frees it when the holder process finishes. important-p should be nil for locks which are managed completely by the application, as it is wasteful to record all locks in a global list if there is no need to free them automatically. This might be appropriate when two processes sharing a lock must both be running for the system to be consistent. If one process dies, then the other one kills itself. Thus the system does not need to worry about freeing the lock because no process could be waiting on it forever after the first process dies. The default value of important-p is nil.

safep controls whether lock is safe. A safe lock gives an error if process-unlock is called on it when it is not locked by the current process, and potentially in other 'dangerous' circumstances. An unsafe lock does not signal these errors. The default value of safep is t.

recursivep, when true, allows lock to be locked recursively. Trying to lock a lock that is already locked by the current thread just increments its lock count. If lock is created with recursivep nil then trying to lock again causes an error. This is useful for debugging code where lock is never expected to be claimed recursively. The default value of recursivep is t.

When sharing is false (the default), lock is an ordinary lock that can only be locked by one process at a time. When sharing is true, lock is a "sharing" lock, which supports sharing and exclusive locking. At any given time, a sharing lock may be free, or it may be locked for sharing by any number of threads or locked for exclusive use by a single thread. Note that use of sharing locks requires a different set of functions and macros from the set that is used for ordinary locks. See 19.4.1 Recursive and sharing locks for details.

Examples
CL-USER 3 > (setq *my-lock* (mp:make-lock 
                             :name "my-lock"))
#<MP:LOCK "my-lock" Unlocked 2008CAC7>
 
CL-USER 4 > (mp:process-lock *my-lock*)
T
 
CL-USER 5 > *my-lock*
#<MP:LOCK "my-lock" Locked once by "CAPI Execution Listener 1" 2008CAC7>
 
CL-USER 6 > (mp:process-lock *my-lock*)
T
 
CL-USER 7 > *my-lock*
#<MP:LOCK "my-lock" Locked 2 times by "CAPI Execution Listener 1" 2008CAC7>
See also

lock
*current-process*
lock-recursive-p
process-lock
process-unlock
schedule-timer
with-lock
19.4 Locks


LispWorks® User Guide and Reference Manual - 01 Dec 2021 19:30:51