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 by attr.
  • pthread_condattr_setpshared() shall set the process-shared attribute in an initialized attributes object referenced by attr.

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 the attr argument to pthread_condattr_getpshared() or pthread_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 of attr into the object referenced by the pshared parameter. 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 returning EINVAL.

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>


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