PTHREAD_M...ETPSHARED(3P)
β¨ PTHREAD_M...ETPSHARED π β the POSIX Programmer's Manual page
okay bestie so this is a page out of the POSIX Programmer's Manual (yes, that one, the icon itself). Quick heads up before we get into it: π«Ά
β οΈ This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (so go check the corresponding Linux manual page for the tea on Linux behavior), or the interface might not even be implemented on Linux at all. π
πΈ NAME πΈ
pthread_mutexattr_getpshared, pthread_mutexattr_setpshared β get and set the process-shared attribute
the way these two are literally just the getter and the setter for one single little attribute?? iconic duo behavior fr fr π
π 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);
note the restrict keywords, bestie β they're right there in the original and they are staying right there. no cap. β¨
π DESCRIPTION π
so here's the whole vibe:
pthread_mutexattr_getpshared()shall obtain the value of the process-shared attribute from the attributes object referenced byattr. it's giving "lemme see what you set." πpthread_mutexattr_setpshared()shall set the process-shared attribute in an initialized attributes object referenced byattr. it's giving "okay setting it now, periodt." π
now the actual lore: the process-shared attribute gets set to PTHREAD_PROCESS_SHARED to permit a mutex to be operated upon by any thread that has access to the memory where the mutex is allocated β even if that mutex is allocated in memory that's shared by multiple processes. yes, multiple processes, not just threads. multi-process main character energy. π
for further requirements, see Section 2.9.9, Synchronization Object Copies and Alternative Mappings. (yes go read it, iykyk π)
the default value of the attribute shall be PTHREAD_PROCESS_PRIVATE. so if you don't touch it, it stays private. shy little default. π
π undefined behavior alert π β the behavior is undefined if the value specified by theattrargument topthread_mutexattr_getpshared()orpthread_mutexattr_setpshared()does not refer to an initialized mutex attributes object. so likeβ¦ initialize your objects, bestie. don't do crimes. π¨
β RETURN VALUE β
- Upon successful completion,
pthread_mutexattr_setpshared()shall return zero; otherwise, an error number shall be returned to indicate the error. zero is the good number, slay. β¨ - Upon successful completion,
pthread_mutexattr_getpshared()shall return zero and store the value of the process-shared attribute ofattrinto the object referenced by thepsharedparameter. otherwise, an error number shall be returned to indicate the error. so you get the return code and the value stuffed intopshared. two for one. π
π¦ ERRORS π¦
pthread_mutexattr_setpshared() may fail if:
EINVALβ the new value specified for the attribute is outside the range of legal values for that attribute. basically you tried to set it to something that isn't a real option. not the move. π
also, these functions shall not return an error code of [EINTR]. nope, not a thing here. don't come looking for it. π
π heads up: the following sections are informative β meaning they're the commentary track, not the actual rules. π§
π EXAMPLES π
None.
(yeah. literally none. the void. we respect it. π³οΈβ¨)
π APPLICATION USAGE π
None.
(again, none! consistency queen. π)
π§ RATIONALE π§
so if an implementation detects that the value specified by the attr argument to pthread_mutexattr_getpshared() or pthread_mutexattr_setpshared() does not refer to an initialized mutex attributes object, it is recommended that the function should fail and report an [EINVAL] error.
that's a recommendation, not a hard requirement β but honestly bestie, it's the polite thing to do. π«Ά
π₯ FUTURE DIRECTIONS π₯
None.
(three "None"s deep and we are still thriving. πΈ)
π SEE ALSO π
go check these out, they're all part of the same little friend group:
pthread_cond_destroy()pthread_create()pthread_mutex_destroy()pthread_mutexattr_destroy()
and from The Base Definitions volume of POSIX.1β2017: <pthread.h> β the header, the blueprint, the source of truth. π
π COPYRIGHT π
okay this part is important and we're keeping every single word, so:
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group.
In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. (referee = the one that actually decides. respect the referee. π)
The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page, bestie!! π this one came from IEEE/The Open Group, 2017, and the header up top reads PTHREAD_M...ETPSHARED(3P) (yes, with the little ... in the middle, we love a mystery). go forth, share your mutexes across processes responsibly, and don't forget to initialize your attributes objects. mwah. πβ¨πΈ
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- 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-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms