qthread_incr(3)

πŸ“¦ version 1.22^20251007gitcedb1fc, in fedora 43, fedora 44

πŸ’– qthread_incr β€” atomically increment a value πŸ’–

okay bestie, welcome to libqthread's little family of atomic incrementers. this page covers three of them: qthread_incr, qthread_dincr, and qthread_fincr. yes, they all do the same vibe, just for different types. no cap.


✨ SYNOPSIS ✨

#include <qthread.h>

aligned_t
qthread_incr (aligned_t *operand, int incr);

float
qthread_fincr (float *operand, float incr);

double
qthread_dincr (double *operand, double incr);

πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea. this function atomically increments the variable that operand points at, by incr. that's it, that's the whole thing. it's literally the thread-safe version of this:

*operand += incr;

but like… safe. 🌸 because doing += from multiple threads is giving chaos energy and we don't do that here.

under the hood, bestie, it uses architecture-specific assembly to pull this off β€” lowkey iconic. but on unrecognized hardware it falls back to using qthread_lock() and qthread_unlock() so it stays thread-safe no matter what. gotta have a backup plan, periodt. πŸ’…

ordinarily, though, it does not use any of the available address locking mechanisms. normally that's just not the move. there are exceptions though πŸ‘€ β€” and here's the one:

  • on 32-bit PowerPC, which has 64-bit doubles but does not have a 64-bit atomic load-and-reserve-word instruction β€” on this architecture we're forced to use qthread_lock() and qthread_unlock(). no choice, it's giving mandatory. 😭

πŸŽ€ RETURN VALUE πŸŽ€

these functions will return the value *operand had before the increment was performed. so like, the old value. the pre-glow-up value. remember that, it matters fr fr.


🌈 SEE ALSO 🌈


and that's the whole page, bestie 🫢 this one's from the libqthread manual, dated JULY 2008 β€” yeah she's an elder but she still ate πŸ’€βœ¨ go forth and increment atomically, mwah πŸ’–

πŸ“¦ where this page comes from