tsv incr
Adds an integer to an element of a shared array.
tsv::incr ARRAY ELEMENT ?N?
Description
The command tsv::incr adds N, 1 by default, to the integer in the element and gives the new value. An element that does not exist starts at 0. The read and the write are one step under the lock of the array, so two threads that count in one element lose no count.
Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
| ARRAY | array name | required | The name of the shared array. |
| ELEMENT | string | required | The name of the element. |
| N | integer | 1 | The amount to add. |
Returns
The new integer.
Examples
% tsv::incr c n
1
% tsv::incr c2 n 5
> tsv::incr c2 n -2
3
Errors
% tsv::incr
wrong # args: should be "tsv::incr array key ?args?"
-errorcode TCL WRONGARGS
% tsv::set c s abc
> tsv::incr c s
expected integer but got "abc"
-errorcode TCL VALUE NUMBER
% tsv::incr c n x
expected integer but got "x"
-errorcode TCL VALUE NUMBER
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