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

NAME

6       zmq_atomic_counter_set - set atomic counter to new value
7

SYNOPSIS

9       void zmq_atomic_counter_set (void *counter, int value);
10

DESCRIPTION

12       The zmq_atomic_counter_set function sets the counter to a new value, in
13       a threadsafe fashion. The largest value that is guaranteed to work
14       across all platforms is 2^31-1. This function uses platform specific
15       atomic operations.
16

RETURN VALUE

18       The zmq_atomic_counter_set() function has no return value.
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_inc(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                         01/21/2023           ZMQ_ATOMIC_COUNTER_S(3)
Impressum