ZMQ_ATOMIC_COUNTER_S(3)

πŸ’… zmq_atomic_counter_set(3) β€” the 0MQ Manual, bestie edition

okay so we're in the 0MQ manual and today's episode is zmq_atomic_counter_set(3), aka the girl whose whole job is just setting a number. no drama, no notes, she simply serves.


✨ NAME ✨

zmq_atomic_counter_set β€” set atomic counter to new value


πŸŽ€ SYNOPSIS πŸŽ€

void zmq_atomic_counter_set (void *counter, int value);

that's it. that's the whole signature. short queen πŸ‘‘


πŸ¦‹ DESCRIPTION πŸ¦‹

so zmq_atomic_counter_set sets the counter to a new value, and it does it in a threadsafe fashion β€” meaning multiple threads can be doing their little thing and it's still gonna behave. no cap.

the largest value that is guaranteed to work across all platforms is 2^31-1. so like, stay in that lane, bestie, unless you enjoy chaos.

under the hood this function uses platform specific atomic operations. it's giving "I don't do the work myself, I delegate to the locals" and honestly? respect.


πŸ’œ RETURN VALUE πŸ’œ

zmq_atomic_counter_set() has no return value. it returns nothing. void. it says its piece and leaves. main character energy fr fr.


🌸 EXAMPLE 🌸

test code for atomic counters, here it is, verbatim, character for character, do not touch:

void *counter = zmq_atomic_counter_new ();
assert (zmq_atomic_counter_value (counter) == 0);
assert (zmq_atomic_counter_inc (counter) == 0);
assert (zmq_atomic_counter_inc (counter) == 1);
assert (zmq_atomic_counter_inc (counter) == 2);
assert (zmq_atomic_counter_value (counter) == 3);
assert (zmq_atomic_counter_dec (counter) == 1);
assert (zmq_atomic_counter_dec (counter) == 1);
assert (zmq_atomic_counter_dec (counter) == 0);
zmq_atomic_counter_set (counter, 2);
assert (zmq_atomic_counter_dec (counter) == 1);
assert (zmq_atomic_counter_dec (counter) == 0);
zmq_atomic_counter_destroy (&counter);
return 0;

look at her go β€” new counter, zero, increment up to 3, decrement back down, then zmq_atomic_counter_set (counter, 2) swoops in and just resets the vibe, and the decs pick up from there. ate. πŸ”₯


🌈 SEE ALSO 🌈

the whole friend group, go say hi 🫢


πŸ‘‘ AUTHORS πŸ‘‘

this page was written by the 0MQ community. to make a change please read the 0MQ Contribution Policy at http://www.zeromq.org/docs:contributing. (yes, that's the real link, yes, it's a colon, no, I'm not editing it, it's not mine to edit πŸ’€)


0MQ 4.3.5 Β· 10/09/2023 Β· that's the version and the date, babes β€” and that's the whole page. mwah πŸ’‹ zmq_atomic_counter_set(3) out. ✨

πŸ“¦ where this page comes from