ZMQ_ATOMIC_COUNTER_D(3)

✨ NAME ✨

ok so this is zmq_atomic_counter_destroy β€” it's the function that destroys an atomic counter. like, it takes it out. bye bestie πŸ’…

it lives in section 3 of the 0MQ manual, and yeah it's part of the whole 0MQ/ZeroMQ fam 🫢


🌸 SYNOPSIS 🌸

void zmq_atomic_counter_destroy (void **counter_p);

look at that. no return value. just vibes and destruction. ✨


πŸ’– DESCRIPTION πŸ’–

ok so here's the tea πŸ“ β€” zmq_atomic_counter_destroy does exactly what it says on the tin: it destroys an atomic counter and nullifies its reference. two jobs, one function, she's efficient, we love that for her πŸ‘‘

but listen, this is the part where you have to pay attention, bestie, no scrolling past this one πŸ™ˆ β€” you pass the address of an atomic counter (void **) rather than the counter itself. address of. not the counter. the address. i cannot stress this enough, this is the entire plot twist of this manpage.

⚠️ and like… you must destroy all the counters that you create. every single one. otherwise you get memory leakage and nobody wants that, it's giving leaks, it's giving sad, it's giving your future self crying at a valgrind report 😭

also, fun fact (not a fun fact, it's just a fact): this function uses platform specific atomic operations. so under the hood it's doing little platform-specific magic tricks. slay πŸ”₯


πŸŽ€ RETURN VALUE πŸŽ€

zmq_atomic_counter_destroy() has no return value. nothing. nada. it just does the thing and leaves. main character energy fr fr ✨


πŸ¦‹ EXAMPLE πŸ¦‹

here's some test code for atomic counters, so you can see the whole lifecycle β€” birth, math, and destruction 🌈

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;

see that very last bit before the return? zmq_atomic_counter_destroy (&counter); β€” that's the &. the address. the whole point. she's there, she's iconic, she's the function πŸ’œ


πŸ’œ SEE ALSO πŸ’œ

your little counter squad, go read all of them, they're all connected iykyk:


πŸ‘‘ AUTHORS πŸ‘‘

this page was written by the 0MQ community πŸ’–. and if you wanna make a change (respect, go off), please read the 0MQ Contribution Policy at http://www.zeromq.org/docs:contributing.


and that's the whole page, bestie 🧚 this one came to you from 0MQ 4.3.5, dated 10/09/2023 β€” go forth, destroy your counters, and remember the & or i will find you πŸ’…βœ¨πŸŒΈ

πŸ“¦ where this page comes from