tsv lock
Runs a script while the calling thread holds the lock of a shared array.
tsv::lock ARRAY ARG ?ARG ...?
Description
The command tsv::lock locks ARRAY, runs the script, and unlocks the array, also after an error. Two or more ARG words are joined with spaces into one script, as eval does. The lock is recursive for its thread, so each tsv command of the script on that array runs in the same lock, and no other thread sees the array between two of those commands. The array does not need to exist.
Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
| ARRAY | array name | required | The name of the shared array. |
| ARG | script | required | The script, or words that form it. |
Returns
The result of the script.
Examples
# The read and the write are one step for the other threads.
% tsv::set acct a 10
> tsv::lock acct {
> set v [tsv::get acct a]
> tsv::set acct a [expr {$v - 3}]
> }
7
% tsv::lock z tsv::set z k v
v
Errors
% tsv::lock z
wrong # args: should be "tsv::lock array arg ?arg...?"
-errorcode TCL WRONGARGS
% tsv::lock z {error inner}
inner
-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