thread eval
Runs a script while the calling thread holds a mutex.
thread::eval ?-lock MUTEX? ARG ?ARG ...?
Description
The command thread::eval locks MUTEX, or a mutex of the group with no -lock, runs the script, and unlocks the mutex, also after an error. Two or more ARG words are joined with spaces into one script, as eval does.
Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
| ARG | script | required | The script, or words that form it. |
Options
| Option | Type | Default | Description |
|---|---|---|---|
-lock | mutex handle | none | Holds this mutex in place of the mutex of the group. |
-lock MUTEX
Holds this mutex in place of the mutex of the group.
MUTEX is a handle of thread::mutex create. The calling thread must not hold an exclusive MUTEX already.
% set m [thread::mutex create]
> thread::eval -lock $m set q 3
3% thread::eval -lock mid99 {expr 1}
no such mutex "mid99"
-errorcode NONE
% set m [thread::mutex create]
> thread::mutex lock $m
> thread::eval -lock $m {expr 1}
locking the same exclusive mutex twice from the same thread
-errorcode NONEReturns
The result of the script.
Examples
% thread::eval {expr {6 * 7}}
42
% set m [thread::mutex create]
> thread::eval -lock $m {set z 1}
1
% thread::eval set zz 2
2
Errors
% thread::eval
wrong # args: should be "thread::eval ?-lock <mutexHandle>? arg ?arg...?"
-errorcode TCL WRONGARGS
% thread::eval {error inside}
inside
-errorcode NONE
Facts
- Capability
thread. A new interpreter does not have it until the host turns it on.- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztcl 1.0.0-beta.1