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

NAME

6       zmq_atomic_counter_dec - decrement an atomic counter
7

SYNOPSIS

9       int zmq_atomic_counter_dec (void *counter);
10

DESCRIPTION

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

RETURN VALUE

17       The zmq_atomic_counter_dec() function returns 1 if the counter is
18       greater than zero after decrementing, or zero if the counter reached
19       zero.
20

EXAMPLE

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

SEE ALSO

41       zmq_atomic_counter_new(3) zmq_atomic_counter_set(3)
42       zmq_atomic_counter_inc(3) zmq_atomic_counter_value(3)
43       zmq_atomic_counter_destroy(3)
44

AUTHORS

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