qthread_syncvar_readFE(3)

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

πŸ’– qthread_syncvar_readFE β€” from libqthread (section 3) πŸ’–

okay bestie, sit down, hydrate, and let's talk about the most dramatic little function in libqthread 🫢


✨ NAME ✨

qthread_syncvar_readFE β€” she waits for the syncvar to be full, then copies its data and empties it πŸ’…


🌸 SYNOPSIS 🌸

#include <qthread.h>

int
qthread_syncvar_readFE (uint64_t * restrict dest, syncvar_t * restrict
src);

πŸ¦‹ DESCRIPTION πŸ¦‹

So here's the vibe: this function waits for memory to become full, and then empties it. That's the whole personality. πŸŽ€

When memory becomes full, only one thread blocked like this will be awoken. Not two. Not "whoever gets there first." One. The others stay seated, bestie. πŸ’€

Data is read from src and stored in dest. And here's the cute part β€” dest may be NULL, in which case the data will not be copied. She just empties. No notes. πŸ™ˆ

The semantics of readFE are, in order:

  1. src's FEB state must be "full" ⭐
  2. data is copied from src to dest ✨
  3. src's FEB state gets changed from "full" to "empty" πŸ’…

it's giving full β†’ copy β†’ empty, and honestly? iconic. periodt.


πŸ”₯ RETURN VALUE πŸ”₯

On success: the memory address src is marked empty, the memory address dest is filled with the contents of src, and 0 (QTHREAD_SUCCESS) is returned. slay. πŸŽ‰

On error: a non-zero error code is returned. not slay, but at least you know. 😭


πŸ’œ ERRORS πŸ’œ

  • ENOMEM β€” Not enough memory could be allocated for bookkeeping structures. she tried to set up her little admin and there was just nothing left in the budget. πŸ’€
  • QTHREAD_TIMEOUT β€” Could not obtain the lock on the syncvar_t's status bits. This may be caused by many things, including memory corruption, an invalid syncvar, or even absurdly excessive contention (because it's protected by a naive spinlock rather than a fair spinlock). ngl, the naive spinlock is the villain of this story. πŸ™ˆ

🌈 SEE ALSO 🌈

go read the whole friend group, they're all connected iykyk πŸ‘‘


πŸ’– cute sign-off: this page came from libqthread, dated APRIL 2011 β€” yes she's vintage, yes she still ate. mwah. πŸŽ€πŸ’…βœ¨
πŸ“¦ where this page comes from