PTHREAD_MUTEX_CONSISTENT(3)
π pthread_mutex_consistent(3) π
okay bestie, welcome to the Library Functions Manual section of the group chat β this one's from the POSIX threads library (libpthread, -lpthread) and it's honestly kind of a big deal for anyone whose threads keep ghosting them mid-lock. π»
β¨ NAME β¨
pthread_mutex_consistent β make a robust mutex consistent π«Ά
πΈ LIBRARY πΈ
POSIX threads library (libpthread, -lpthread)
π¦ SYNOPSIS π¦
#include <pthread.h>
int pthread_mutex_consistent(pthread_mutex_t *mutex);
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
pthread_mutex_consistent():
_POSIX_C_SOURCE >= 200809L
yes you literally need that macro bestie, glibc does not play about feature test macros π
π DESCRIPTION π
So here's the vibe: this function makes a robust mutex consistent again if it's sitting in an inconsistent state. π
And how does a mutex end up inconsistent, you ask? Not me about to tell you the lore: a mutex can be left in an inconsistent state if its owner terminates while holding the mutex. π In that case, the next owner who acquires the mutex will succeed, and they get notified by a return value of EOWNERDEAD from a call to pthread_mutex_lock(). Like, surprise!! you own the lock now, and also everything it was protecting might be a crime scene. π
The way that pthread_mutex_consistent() is the "okay I cleaned it up, we're good" button. β¨
π RETURN VALUE π
- On success,
pthread_mutex_consistent()returns0. slay. - Otherwise, it returns a positive error number to indicate the error. (positive, not negative, not
errno-flavoured β the return value is the error, iykyk) π
π ERRORS π
EINVALβ The mutex is either not robust or is not in an inconsistent state. (Translation: you're asking the function to fix a vibe that was never broken, or that it literally cannot fix. π§)
β STANDARDS β
POSIX.1-2008.
π HISTORY π
glibc 2.12. πPOSIX.1-2008.
Now for the ancient lore: before pthread_mutex_consistent() got added to POSIX, glibc defined the following equivalent nonstandard function if _GNU_SOURCE was defined:
[[deprecated]]
int pthread_mutex_consistent_np(const pthread_mutex_t *mutex);
This GNU-specific API, which first appeared in glibc 2.4, is nowadays obsolete and should not be used in new programs; since glibc 2.34 it has been marked as deprecated. so like... don't. π« no cap, don't use the _np one, it's giving 2008 and not in the cute vintage way.
π NOTES π
pthread_mutex_consistent() simply informs the implementation that the state (shared data) guarded by the mutex has been restored to a consistent state and that normal operations can now be performed with the mutex. π«Ά
π¨ IMPORTANT BESTIE π¨ It is the application's responsibility to ensure that the shared data has been restored to a consistent state before calling pthread_mutex_consistent(). The function is not doing your cleanup for you. It is not a magical healer. It is a notary. You do the work, it signs the papers. π
π EXAMPLES π
See pthread_mutexattr_setrobust(3). (yes go look, the example lives over there, I'm not retyping it, go read it, ily π«Ά)
π SEE ALSO π
pthread_mutex_lock(3)pthread_mutexattr_getrobust(3)pthread_mutexattr_init(3)pthread_mutexattr_setrobust(3)pthreads(7)
okay that's the whole page, you ate that fr fr π½οΈβ¨ remember: robust mutexes are main character energy but you still have to restore the shared data yourself, no one else is coming to do it for you. ππ«Ά
Linux man-pages 6.20 β dated 2026-02-08 β mwah, that's the version and the date, love u, bye bestie πππ page (PTHREAD_MUTEX_CONSISTENT(3)) closed, periodt. π
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π the page's license: Linux-man-pages-copyleft
- Copyright 2017, Yubin Ruan <ablacktshirt@gmail.com>
- Copyright 2017, Michael Kerrisk <mtk.manpages@gmail.com>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms