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

NAME

6       zmq_atomic_counter_new - create a new atomic counter
7

SYNOPSIS

9       void *zmq_atomic_counter_new (void);
10

DESCRIPTION

12       The zmq_atomic_counter_new function creates a new atomic counter. You
13       can use this in multithreaded applications to do, for example,
14       reference counting of shared objects. The atomic counter is at least 32
15       bits large. This function uses platform specific atomic operations.
16

RETURN VALUE

18       The zmq_atomic_counter_new() function returns the new atomic counter if
19       successful. Otherwise it returns NULL.
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_set(3) zmq_atomic_counter_inc(3)
42       zmq_atomic_counter_dec(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/2022           ZMQ_ATOMIC_COUNTER_N(3)
Impressum