1ZMQ_ATOMIC_COUNTER_I(3)           0MQ Manual           ZMQ_ATOMIC_COUNTER_I(3)
2
3
4

NAME

6       zmq_atomic_counter_inc - increment an atomic counter
7

SYNOPSIS

9       int zmq_atomic_counter_inc (void *counter);
10

DESCRIPTION

12       The zmq_atomic_counter_inc function increments an atomic counter in a
13       threadsafe fashion. This function uses platform specific atomic
14       operations.
15

RETURN VALUE

17       The zmq_atomic_counter_inc() function returns the old value of the
18       counter, before incrementing.
19

EXAMPLE

21       Test code for atomic counters.
22
23           void *counter = zmq_atomic_counter_new ();
24           assert (zmq_atomic_counter_value (counter) == 0);
25           assert (zmq_atomic_counter_inc (counter) == 0);
26           assert (zmq_atomic_counter_inc (counter) == 1);
27           assert (zmq_atomic_counter_inc (counter) == 2);
28           assert (zmq_atomic_counter_value (counter) == 3);
29           assert (zmq_atomic_counter_dec (counter) == 1);
30           assert (zmq_atomic_counter_dec (counter) == 1);
31           assert (zmq_atomic_counter_dec (counter) == 0);
32           zmq_atomic_counter_set (counter, 2);
33           assert (zmq_atomic_counter_dec (counter) == 1);
34           assert (zmq_atomic_counter_dec (counter) == 0);
35           zmq_atomic_counter_destroy (&counter);
36           return 0;
37
38

SEE ALSO

40       zmq_atomic_counter_new(3) zmq_atomic_counter_set(3)
41       zmq_atomic_counter_dec(3) zmq_atomic_counter_value(3)
42       zmq_atomic_counter_destroy(3)
43

AUTHORS

45       This page was written by the 0MQ community. To make a change please
46       read the 0MQ Contribution Policy at
47       http://www.zeromq.org/docs:contributing.
48
49
50
510MQ 4.3.4                         07/23/2022           ZMQ_ATOMIC_COUNTER_I(3)
Impressum