On this page
  1. mtx_lock
  2. Include
  3. Signature & Overview
  4. Notes & Pitfalls
  5. Example

mtx_lock

Prev: thrd_create | Up: threads.h | Next: setjmp.h
Rel: threads.h, Concurrency vs. Parallelism
Ref: cppreference — mtx_lock
Tags: #public #prog #c #stdlib #threads #tier/specialized


Include

#include <threads.h>

Signature & Overview

int mtx_lock(mtx_t *mutex);  /* + mtx_init, mtx_unlock, mtx_destroy */

Acquires a mutual-exclusion lock to guard shared mutable state across threads.

Notes & Pitfalls

Example

// C11 <threads.h> pattern (Linux/glibc 2.28+):
// mtx_t m; mtx_init(&m, mtx_plain);
// mtx_lock(&m); /* critical section */ mtx_unlock(&m);
// mtx_destroy(&m);

Linked from

Related notes