nanomsg next generation NNG  
Home GitHub Documentation

This documentation is for version v1.2.2 of nng, but the latest released version is v1.8.0. see the documentation for v1.8.0 for the most up-to-date information.
nng_cv_wait(3supp)

SYNOPSIS

#include <nng/nng.h>
#include <nng/supplemental/util/platform.h>

void nng_cv_wait(nng_cv *cv);

DESCRIPTION

The nng_cv_wait() waits for the condition variable cv to be signaled by another thread calling either nng_cv_wake() or nng_cv_wake1().

The caller must have 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.)

Any condition may be used or checked, but the condition must be checked, as 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.

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;
    cv_wake(cv);
    nng_mtx_unlock(m);

RETURN VALUES

None.

ERRORS

None.

NNG Reference Manual vv1.2.2 © 2019 Staysail Systems, Inc, © 2018 Capitar IT Group BV
This document is supplied under the MIT License.
nanomsg™ and nng™ are trademarks of Garrett D'Amore.