NNG_CV_UNTIL(3supp)
π 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
cvby calling eithernng_cv_wake()ornng_cv_wake1()π - the system clock β the one tracked by
nng_clock()β reacheswhenβ³
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:
nng_cv_alloc(3supp)nng_cv_wait(3supp)nng_cv_wake(3supp)nng_cv_wake1(3supp)nng_mtx_alloc(3supp)nng_mtx_lock(3supp)nng_mtx_unlock(3supp)nng(7)
π 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
- alpine 3.24: nng-doc 1.11-r0 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms