![]() | ![]() | ![]() | with-lock-held | ![]() |
|
| (lock
&key
whostate)
form*
=> result* | [Macro] |
Purpose
After acquiring a lock or a recursive lock,
execute forms and then release the lock.
Package :portable-threads
Module :portable-threads
Arguments and values
| lock | A lock, a recursive lock, or a condition variable | |
| whostate | A string (default "With Lock Held")
| |
| forms | An implicit progn of forms to be evaluated | |
| results | The values returned by evaluating the last form |
Returns
The values returned by evaluating the last form.
Errors
A thread attempts to re-acquire a (non-recursive)
lock that it holds.
Description
If a thread executes a with-lock-held
that is dynamically inside another with-lock-held involving
the same recursive lock, the inner with-lock-held
simply proceeds as if it had acquired the lock.
See also
make-condition-variable
make-lock
make-recursive-lock
thread-holds-lock-p
thread-whostate
without-lock-held
Examples
Acquire the lock controlling access to a critical section of code:
(with-lock-held (lock :whostate "Waiting for Critical Lock")
(critical-section))
A silly example showing a recursive re-acquisition of a
recursive lock:
(with-lock-held (recursive-lock :whostate "Waiting for Critical Lock")
(with-lock-held (recursive-lock :whostate "Again Waiting for Critical Lock")
(critical-section)))
Acquire the lock associated with condition-variable and then
signal all blocked threads that are waiting on it:
(with-lock-held (condition-variable)
(condition-variable-signal condition-variable))
Note
The whostate value is ignored by
SBCL.
The GBBopen Project
![]() | ![]() | ![]() | with-lock-held | ![]() |