PTHREAD_C...GETPSHARED(3P)
π pthread_condattr_getpshared, pthread_condattr_setpshared π
okay bestie so this one is from the POSIX Programmer's Manual, section 3P β it's the get-and-set situation for the process-shared condition variable attributes and it's honestly giving "small API, big responsibility" β¨
β¨ PROLOG β¨
so like, heads up π«Ά this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ β if that's you, go peek at the corresponding Linux manual page for the deets on Linux behavior. OR the interface might just not be implemented on Linux at all. vibe check accordingly π
π NAME π
pthread_condattr_getpshared, pthread_condattr_setpshared β get and set the process-shared condition variable attributes. that's it, that's the whole job, and they do it flawlessly π
πΈ SYNOPSIS πΈ
#include <pthread.h>
int pthread_condattr_getpshared(const pthread_condattr_t *restrict attr,
int *restrict pshared);
int pthread_condattr_setpshared(pthread_condattr_t *attr,
int pshared);
π¦ DESCRIPTION π¦
okay so, two little functions, two little jobs:
pthread_condattr_getpshared()shall obtain the value of the process-shared attribute from the attributes object referenced byattr.pthread_condattr_setpshared()shall set the process-shared attribute in an initialized attributes object referenced byattr.
now the actual tea β the process-shared attribute gets set to PTHREAD_PROCESS_SHARED to permit a condition variable to be operated upon by any thread that has access to the memory where the condition variable is allocated β even if that condition variable lives in memory that's shared by multiple processes. no cap, cross-process condition variables are real and they're iconic. see Section 2.9.9, Synchronization Object Copies and Alternative Mappings for further requirements, because of course there are further requirements, there always are.
the default value of the attribute is PTHREAD_PROCESS_PRIVATE π«§ (so if you never touched it, it's private, it's minding its own business, it's not sharing with anybody).
π DANGER ZONE: the behavior is undefined if the value specified by theattrargument topthread_condattr_getpshared()orpthread_condattr_setpshared()does not refer to an initialized condition variable attributes object. like. undefined. don't do it. don't be that girl π
β RETURN VALUE β
- If successful,
pthread_condattr_setpshared()shall return zero. otherwise, an error number shall be returned to indicate the error. simple as π - If successful,
pthread_condattr_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.
like yes, zero means slay, nonzero means read the number, it's an error code, it's telling you something π₯
π ERRORS π
pthread_condattr_setpshared() may fail if:
EINVALβ The new value specified for the attribute is outside the range of legal values for that attribute. bestie you gave it a value it does not recognize. it's not mad, it's just returningEINVAL.
also, very important: these functions shall not return an error code of [EINTR]. nope. never. not happening. π
βοΈ
The following sections are informative.
π EXAMPLES π
None. (yes literally none. the examples section said "no thoughts, head empty" and honestly? respect π)
π APPLICATION USAGE π
None. (also empty. the vibes are immaculate but the content is minimal.)
π§ RATIONALE π§
so here's the reasoning, and it's lowkey sensible: if an implementation detects that the value specified by the attr argument to pthread_condattr_getpshared() or pthread_condattr_setpshared() does not refer to an initialized condition variable attributes object, it is recommended that the function should fail and report an [EINVAL] error.
translation: uninitialized attr? the recommendation is to fail loudly, not to guess. communicate. set boundaries. report [EINVAL] π
π« FUTURE DIRECTIONS π«
None. (the future is bright and also unchanged β¨)
π SEE ALSO π
pthread_create()pthread_cond_destroy()pthread_condattr_destroy()pthread_mutex_destroy()
The Base Definitions volume of POSIX.1β2017, <pthread.h>
π COPYRIGHT π
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. 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 to you courtesy of IEEE/The Open Group, 2017 β go forth, initialize your attr, know your PTHREAD_PROCESS_SHARED from your PTHREAD_PROCESS_PRIVATE, and stay undefined-behavior-free πβ¨π
π¦ 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