summaryrefslogtreecommitdiff
path: root/docs/reference/src/thr/nng_mtx_lock.md
blob: be84afe8a52db6228f5e33ee3cbb67bad9761e54 (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
40
# nng_mtx_lock

## NAME

nng_mtx_lock --- lock mutex

## SYNOPSIS

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

void nng_mtx_lock(nng_mtx *mtx);
```

## DESCRIPTION

The `nng_mtx_lock()` acquires exclusive ownership of the mutex _mtx_.
If the lock is already owned, this function will wait until the current
owner releases it with [`nng_mtx_unlock()`][nng_mtx_unlock].

If multiple threads are waiting for the lock, the order of acquisition
is not specified.

> [!NOTE]
> A mutex can _only_ be unlocked by the thread that locked it.

> [!NOTE]
> Mutex locks are _not_ recursive; attempts to reacquire the
> same mutex may result in deadlock or aborting the current program.
> It is a programming error for the owner of a mutex to attempt to
> reacquire it.

## SEE ALSO

[nng_cv_alloc][nng_cv_alloc],
[nng_mtx_alloc][nng_mtx_alloc],
[nng_mtx_unlock][nng_mtx_unlock]

{{#include ../refs.md}}