NNG_CV_UNTIL(3supp)

πŸ“¦ version 1.11, in alpine 3.24

πŸ’… NNG_CV_UNTIL πŸ’…

okay bestie, so this is a page from the NNG Reference Manual β€” section 3supp, entry nng_cv_until. it's a tiny little function but she's lowkey important, so let's get into it 🫢


✨ NAME ✨

nng_cv_until β€” wait for a condition, or bail when the timer runs out ⏰


🌸 SYNOPSIS 🌸

#include <nng/nng.h>

int nng_cv_until(nng_cv *cv, nng_time when);

πŸ’– DESCRIPTION πŸ’–

so nng_cv_until() literally just waits. she's patient. she sits there until one of exactly two things happens, periodt:

  • another thread signals the condition variable cv by calling either nng_cv_wake() or nng_cv_wake1() πŸŽ€
  • the system clock β€” the one tracked by nng_clock() β€” reaches when ⏳

that's it. that's the whole vibe check.

now, the rules, because there are always rules: you must already own the mutex that was used when cv was allocated. this function will drop your ownership of that mutex, and then atomically reacquire it right before it hands control back to you. (the actual waiting part happens without holding the mutex, which is the whole point β€” otherwise everyone else would be locked out 😭)

⚠️ note, and this one matters: you can use or check any condition you want, but you must actually check it β€” because this function can wake up spuriously. like, for no reason. rude but true πŸ’€. the best way to handle that is to put it inside a loop that keeps repeating until the condition tests true.

πŸ¦‹ EXAMPLE πŸ¦‹

here's how she's used in practice, bestie:

Example 1: Waiting for the condition

expire = nng_clock() + 1000; // 1 second in the future
nng_mtx_lock(m);  // assume cv was allocated using m
while (!condition_true) {
    if (nng_cv_until(cv, expire) == NNG_ETIMEDOUT) {
        printf("Time out reached!\n");
        break;
    }
}
// condition_true is true
nng_mtx_unlock(m);

Example 2: Signaling the condition

nng_mtx_lock(m);
condition_true = true;
nng_cv_wake(cv);
nng_mtx_unlock(m);

see how example 2 is the main character who wakes everything up, and example 1 is the one doing the waiting? iconic duo fr fr πŸ‘‘


⭐ RETURN VALUES ⭐

None. literally nothing. she returns void of information πŸ«₯


πŸ’€ ERRORS πŸ’€

None. no error codes, no drama, no surprises. slay 🌈


πŸ”₯ SEE ALSO πŸ”₯

go read these next, i'm obsessed with cross-references:


πŸŽ€ okay that's the whole page! this one's from the NNG Reference Manual, dated 2026-01-13, filed under NNG_CV_UNTIL(3supp) β€” go forth and wait responsibly, bestie πŸ’œπŸ§š

πŸ“¦ where this page comes from