qthread_incr(3)
π 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()andqthread_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
- fedora 43: qthreads-devel 1.22^20251007gitcedb1fc-1.fc43 Β· BSD-3-Clause AND MIT AND dtoa
- fedora 44: qthreads-devel 1.22^20251007gitcedb1fc-2.fc44 Β· BSD-3-Clause AND MIT AND dtoa
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms