summaryrefslogtreecommitdiff
path: root/docs/ref/thr/nng_cv_alloc.adoc
blob: cd0d5975873b0ceb067bcd6d396ee2fdde37b424 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
## nng_cv_alloc

Allocate condition variable.

### Synopsis

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

typedef struct nng_cv nng_cv;

int nng_cv_alloc(nng_cv **cvp, nng_mtx *mtx);
```

### Description

The `nng_cv_alloc` function allocates a condition variable, using the mutex _mtx_, and returns it in _cvp_.

Every condition variable is associated with a mutex, which must be owned when a thread waits for the condition using xref:nng_cv_wait.adoc[`nng_cv_wait`] or xref:nng_cv_until.adoc[`nng_cv_until`].
The mutex must also be owned when signaling the condition using the xref:nng_cv_wake.adoc[`nng_cv_wake`] or xref:nng_cv_wake1.adoc[`nng_cv_wake1`] functions.

### Return Values

This function returns 0 on success, and non-zero otherwise.

### Errors

[horizontal]
`NNG_ENOMEM`:: Insufficient free memory exists.

### See Also

xref:nng_cv_free.adoc[nng_cv_free],
xref:nng_cv_until.adoc[nng_cv_until],
xref:nng_cv_wait.adoc[nng_cv_wait],
xref:nng_cv_wake.adoc[nng_cv_wake],
xref:nng_cv_wake1.adoc[nng_cv_wake1],
xref:nng_mtx_alloc.adoc[nng_mtx_alloc]