PTHREAD_MUTEX_CONSISTENT_NP(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() returns 0. 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 πŸ’–


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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms