![]() | ![]() | ![]() | with-lock-held | ![]() |
| ( lock &key whostate) | [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 | |
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
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
(with-lock-held (condition-variable) (condition-variable-signal condition-variable))
Note
The whostate value is ignored by
SBCL.
The GBBopen Project
![]() | ![]() | ![]() | with-lock-held | ![]() |