beetlebug▾
/

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

ArgumentTypeDefaultDescription
ARRAYarray namerequiredThe name of the shared array.
ELEMENTstringrequiredThe name of the element.
Ninteger1The 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

See also