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 by attr into the location pointed to by pshared. it's the reading one 🫢
  • pthread_mutexattr_setpshared() β€” sets the value of the process-shared attribute of the mutex attributes object referred to by attr to the value specified in pshared. 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 in pshared is invalid. you gave it something it does not know, and it is politely declining πŸ™ˆ
  • ENOTSUP β€” pshared is PTHREAD_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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms