pthread_mutex_lock(3)

pthread_mutex_lock3

Lock a mutex

Usage

#include <pthread.h>

int

pthread_mutex_lock(pthread_mutex_t *mutex);

Library

POSIX Threads Library (libpthread, -lpthread)

Overview

The pthread_mutex_lock() function locks mutex. If the mutex is already locked, the calling thread will block until the mutex becomes available.

Return values

If successful, pthread_mutex_lock() will return zero, otherwise an error number will be returned to indicate the error.

Errors

The pthread_mutex_lock() function will fail if:

[EINVAL]

The value specified by mutex is invalid.

[EDEADLK]

A deadlock would occur if the thread blocked waiting for mutex.

[EOWNERDEAD]

The argument mutex points to a robust mutex and the process containing the previous owning thread terminated while holding the mutex lock. The lock was granted to the caller and it is up to the new owner to make the state consistent.

[ENOTRECOVERABLE]

The state protected by the mutex is not recoverable.

Releases

79 releases since FreeBSD 2.2.8-RELEASE; the text changed 46 times.

  1. 2.2.8–3.2
  2. 3.3–3.4
  3. 3.5–3.5.1
  4. 4.0
  5. 4.1–4.2
  6. 4.3
  7. 4.4
  8. 4.5–4.11
  9. 5.0
  10. 5.1–5.2.1
  11. 5.3
  12. 5.4
  13. 5.5
  14. 6.0
  15. 6.1–6.3
  16. 6.4
  17. 7.0
  18. 7.1
  19. 7.2
  20. 7.3
  21. 7.4
  22. 8.0
  23. 8.1
  24. 8.2
  25. 8.3
  26. 8.4
  27. 9.0
  28. 9.1
  29. 9.2
  30. 9.3
  31. 10.0
  32. 10.1
  33. 10.2
  34. 10.3
  35. 10.4
  36. 11.0
  37. 11.1
  38. 11.2
  39. 11.3
  40. 11.4
  41. 12.0
  42. 12.1
  43. 12.2
  44. 12.3
  45. 12.4
  46. 13.0–13.2
  47. 13.3–16.0

Standards

The pthread_mutex_lock() function conforms to ISO/IEC 9945-1:1996 (“POSIX.1”).

From base 16.0-CURRENT-20261027-61c70dc16a79 in FreeBSD 16.0-CURRENT (2026-10-27). Parsed by carta from the page's mdoc source.