NNG_CV_WAIT(3supp)

πŸ“¦ version 1.11, in alpine 3.24

🌸 NAME 🌸

nng_cv_wait β€” wait for condition. This cutie lives in the NNG Reference Manual, section 3supp (folding the manual name in right here, bestie, instead of copying that header line πŸ’–).


✨ SYNOPSIS ✨

#include <nng/nng.h>

void nng_cv_wait(nng_cv *cv);

πŸ’… DESCRIPTION πŸ’…

Okay so nng_cv_wait() waits for the condition variable cv to be signaled by another thread calling either nng_cv_wake() or nng_cv_wake1(). That's the whole vibe πŸ’….

The caller must have ownership of the mutex that was used when cv was allocated. This function will drop the ownership of that mutex, and reacquire it atomically just before returning to the caller. (The waiting is done without holding the mutex.) No cap, that part is important πŸ”₯.

Note 🫢 Any condition may be used or checked, but the condition must be checked, because it is possible for this function to wake up spuriously 😭. The best way to do this is inside a loop that repeats until the condition tests for true. Protect your peace and loop it, bestie.

πŸŽ€ EXAMPLE πŸŽ€

The following example demonstrates use of this function:

Example 1: Waiting for the condition

nng_mtx_lock(m);  // assume cv was allocated using m
while (!condition_true) {
    nng_cv_wait(cv);
}
// 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);

πŸ¦‹ RETURN VALUES πŸ¦‹

None. Literally none. ✨


πŸ’€ ERRORS πŸ’€

None. Also none. Iconic, honestly.


πŸ”₯ SEE ALSO πŸ”₯


That's the whole page, bestie πŸ’– β€” source/version: NNG Reference Manual / NNG_CV_WAIT(3supp), dated 2026-01-13. Periodt. 🫢🌈

πŸ“¦ where this page comes from