ZMQ_ATOMIC_COUNTER_V(3)

✨ ZMQ_ATOMIC_COUNTER_V(3) ✨

okay bestie, welcome to the 0MQ Manual πŸ’– β€” yes we're in section 3, the library-functions girlies.


🌸 NAME 🌸

zmq_atomic_counter_value β€” return value of atomic counter πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

int zmq_atomic_counter_value (void *counter);

short, sweet, takes a void * and hands you back an int. that's it. that's the whole vibe.


πŸ’… DESCRIPTION πŸ’…

so. the zmq_atomic_counter_value function returns the value of an atomic counter that you made earlier with zmq_atomic_counter_new(). like, you built the counter, now you wanna peek at what's inside it. 🫢

and the way it does that? platform specific atomic operations, no cap. it's not doing anything sketchy, it's just using whatever fancy atomic primitives your platform ships with. lowkey iconic of it honestly. ✨


πŸ‘‘ RETURN VALUE πŸ‘‘

zmq_atomic_counter_value() returns the value of the atomic counter. πŸŽ€

⚠️ bestie. listen. if counter does NOT point to an atomic counter created by zmq_atomic_counter_new(), the behaviour is undefined. not "a little weird", not "slightly off" β€” undefined undefined. πŸ’€ so please pass it a real counter. i am begging.

🌈 EXAMPLE 🌈

test code for atomic counters, and honestly it's a little journey: 🧚

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;

watch it climb 0 β†’ 1 β†’ 2, peek at 3, come back down, get set to 2, come back down again, and then get yeeted by zmq_atomic_counter_destroy. the character development? unmatched. πŸ”₯


πŸ“ SEE ALSO πŸ“

the whole friend group fr fr 🫢 go read them too.


πŸ’œ 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. come contribute bestie, the group chat is open. ✨


and that's the whole page!! mwah πŸ’… this was 0MQ 4.3.5, dated 10/09/2023 β€” sending you off with kisses and a clean build, bestie. πŸŽ€ πŸ’– 🌸

πŸ“¦ where this page comes from