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

NextPrevUpTopContentsIndex

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 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.

sharing, when true, causes lock to be a "sharing" lock object, 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. Sharing locks are handled by different functions and methods from non-sharing locks.

Example
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
Locks


LispWorks User Guide and Reference Manual - 20 Sep 2017

NextPrevUpTopContentsIndex