ZMQ_ATOMIC_COUNTER_N(3)

✨ ZMQ_ATOMIC_COUNTER_N(3) ✨

okay so bestie, this is a page from the 0MQ Manual and we're about to get so into it πŸ’–


πŸŽ€ NAME πŸŽ€

zmq_atomic_counter_new β€” create a new atomic counter πŸ‘‘


πŸ¦‹ SYNOPSIS πŸ¦‹

void *zmq_atomic_counter_new (void);

🌸 DESCRIPTION 🌸

So the zmq_atomic_counter_new function creates a new atomic counter. That's it, that's the job πŸ’…

You can use this in multithreaded applications to do, for example, reference counting of shared objects. Like, multiple threads all touching the same counter and nobody's stepping on anybody's toes. iconic behaviour fr fr.

The atomic counter is at least 32 bits large. Yes, at least β€” she's not gonna be tiny, don't worry.

This function uses platform specific atomic operations. iykyk πŸ”₯


⭐ RETURN VALUE ⭐

The zmq_atomic_counter_new() function returns the new atomic counter if successful. Otherwise it returns NULL. 😭

not the NULL jump scare. bestie, if you see NULL come back, something went wrong and you gotta handle it, okay? 🫢

πŸ’– EXAMPLE πŸ’–

Test code for atomic counters. Look at her go:

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;

the way she increments and decrements and never once loses count… main character energy, no cap 🌈


πŸ” SEE ALSO πŸ”

go read her sisters, they're all slaying in their own lanes πŸ’œ


πŸ‘‘ 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.


and that's the whole page, bestie πŸŽ€ this was 0MQ 4.3.5, dated 10/09/2023, and honestly? she ate. mwah πŸ’…βœ¨

πŸ“¦ where this page comes from