ZMQ_ATOMIC_COUNTER_D(3)

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

okay so real quick, the manual name is 0MQ Manual and this page is ZMQ_ATOMIC_COUNTER_D(3). yes it's giving "I know her". let's get into it πŸŽ€


✨ NAME ✨

zmq_atomic_counter_dec β€” decrement an atomic counter. that's it. that's the whole job. she does one thing and she does it well πŸ’…


✨ SYNOPSIS ✨

int zmq_atomic_counter_dec (void *counter);

✨ DESCRIPTION ✨

so like, the zmq_atomic_counter_dec function decrements an atomic counter in a threadsafe fashion, no cap. 🧡✨

and the way it does that? it uses platform specific atomic operations. so like, it's not doing anything sketchy, it's letting your platform handle the heavy lifting. trust. πŸ‘‘


✨ RETURN VALUE ✨

zmq_atomic_counter_dec() returns:

  • 1 β€” if the counter is greater than zero after decrementing 🫢
  • 0 β€” if the counter reached zero πŸ’€

so basically it's telling you "we still got some left" or "we hit the floor". cute, informative, iconic. ⭐


✨ EXAMPLE ✨

test code for atomic counters, bestie. 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;

like… she counts up, she counts down, she resets, she does it again, she destroys herself. main character energy fr fr πŸ”₯


✨ SEE ALSO ✨

go read her friends, they're all slaying too:


✨ AUTHORS ✨

this page was written by the 0MQ community 🫢 and if you wanna make a change, please read the 0MQ Contribution Policy at http://www.zeromq.org/docs:contributing. they'd literally love that for you πŸ’–


and that's a wrap on ZMQ_ATOMIC_COUNTER_D(3), brought to you by 0MQ 4.3.5 and dated 10/09/2023. mwah, go decrement something responsibly πŸ’…βœ¨

πŸ“¦ where this page comes from