pthread_mu...getpshared(3)
π pthread_mu...getpshared(3) β Library Functions Manual
okay bestie, sit down, hydrate, and let me tell you about the cutest little pair of functions in the POSIX threads library π this one lives in section 3 of the manual (that's pthread_mu...getpshared(3) for the search bar girlies) and it's about one very specific lil' mutex attribute.
π NAME
pthread_mutexattr_getpshared, pthread_mutexattr_setpshared β get/set process-shared mutex attribute β¨
One gets, one sets, they're a duo, they're a package deal, no cap.
π LIBRARY
POSIX threads library β link it with libpthread, -lpthread π§΅
πΈ SYNOPSIS
#include <pthread.h>
int pthread_mutexattr_getpshared(
const pthread_mutexattr_t *restrict attr,
int *restrict pshared);
int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr,
int pshared);
look at that restrict action. she's careful with her pointers. iconic behavior honestly π
β¨ DESCRIPTION
These two functions get and set the process-shared attribute inside a mutex attributes object. And listen, this attribute is not a vibe-only detail β it must be set appropriately, or the mutex you create with this attributes object won't operate correctly and efficiently. it's giving "do it right or don't do it at all" π
The process-shared attribute can be one of these two values:
PTHREAD_PROCESS_PRIVATEβ mutexes made with this attributes object are meant to be shared only among threads in the same process that initialized the mutex. This is the default value for the process-shared mutex attribute (so if you do nothing, this is what you get, no thoughts head empty π).PTHREAD_PROCESS_SHAREDβ mutexes made with this attributes object can be shared between any threads that have access to the memory containing the object, and yes, that includes threads in different processes. cross-process communication era fr fr π
And now the actual moves:
pthread_mutexattr_getpshared()β places the value of the process-shared attribute of the mutex attributes object referred to byattrinto the location pointed to bypshared. it's the reading one π«Άpthread_mutexattr_setpshared()β sets the value of the process-shared attribute of the mutex attributes object referred to byattrto the value specified inpshared. it's the writing one βοΈ
β οΈ now the serious bit, bestie: if attr does not refer to an initialized mutex attributes object, the behavior is undefined. undefined is not a vibe. undefined is chaos. do not pass go π
π₯ RETURN VALUE
On success, these functions return 0. On error, they return a positive error number. that's it, that's the whole deal, the numbers don't lie β¨
π ERRORS
pthread_mutexattr_setpshared() can fail with the following errors:
EINVALβ the value specified inpsharedis invalid. you gave it something it does not know, and it is politely declining πENOTSUPβpsharedisPTHREAD_PROCESS_SHARED, but the implementation does not support process-shared mutexes. so you asked for the fancy cross-process thing and this system said "we don't do that here" π
π STANDARDS
POSIX.1-2008. certified, official, in the standards π
π°οΈ HISTORY
POSIX.1-2001. so yeah, she's been around. seasoned. mother is mothering π
π¦ SEE ALSO
and that's the whole page, bestie!! go forth and set your attributes responsibly π
this was brought to you by Linux man-pages 6.20, dated 2026-02-08 β mwah, love u, bye πππ«Ά
π¦ 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, 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