PTHREAD_ATTR_GETSCOPE(3P)

πŸ’… PTHREAD_ATTR_GETSCOPE(3P) πŸ’…

okay so this is from the POSIX Programmer's Manual bestie, and we're doing pthread_attr_getscope and pthread_attr_setscope today. hold onto your scrunchie.

🌸 PROLOG 🌸

lowkey important heads up first: this 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 deets on Linux behavior), or the interface may literally not be implemented on Linux at all. πŸ™ˆ


✨ NAME ✨

pthread_attr_getscope, pthread_attr_setscope β€” get and set the contentionscope attribute (REALTIME THREADS) 🧚


πŸŽ€ SYNOPSIS πŸŽ€

#include <pthread.h>

int pthread_attr_getscope(const pthread_attr_t *restrict attr,
    int *restrict contentionscope);
int pthread_attr_setscope(pthread_attr_t *attr, int contentionscope);

πŸ¦‹ DESCRIPTION πŸ¦‹

so basically, pthread_attr_getscope() and pthread_attr_setscope() shall get and set (respectively, bestie, in that order) the contentionscope attribute inside the attr object. πŸ’«

the contentionscope attribute may have these values:

  • PTHREAD_SCOPE_SYSTEM β€” signifying system scheduling contention scope
  • PTHREAD_SCOPE_PROCESS β€” signifying process scheduling contention scope

both of those symbols are defined in the <pthread.h> header, periodt.

πŸ’€ the behavior is undefined if the value specified by the attr argument to pthread_attr_getscope() or pthread_attr_setscope() does not refer to an initialized thread attributes object. like, we're in undefined territory, not cute, do not do this.

🌈 RETURN VALUE 🌈

if it slays (successful), pthread_attr_getscope() and pthread_attr_setscope() shall return zero. otherwise, an error number shall be returned to indicate the error. 😭


πŸ”₯ ERRORS πŸ”₯

pthread_attr_setscope() shall fail if:

  • ENOTSUP β€” an attempt was made to set the attribute to an unsupported value. 🚫

pthread_attr_setscope() may fail if:

  • EINVAL β€” the value of contentionscope is not valid. πŸ™…

also these functions shall not return an error code of [EINTR]. not a thing here.

the following sections are informative (iykyk).


πŸ’œ EXAMPLES πŸ’œ

None.

(yeah. that's it. nothing. the void. 🫢)


πŸ‘‘ APPLICATION USAGE πŸ‘‘

once these attributes have been set, a thread can be created with the specified attributes using pthread_create(). and the way that using these routines does not affect the current running thread? iconic, honestly.

see Section 2.9.4, Thread Scheduling for further details on thread scheduling attributes and their default settings. go read it, bestie, it's giving homework but it's worth it. πŸ“š


⭐ RATIONALE ⭐

if an implementation detects that the value specified by the attr argument to pthread_attr_getscope() or pthread_attr_setscope() does not refer to an initialized thread attributes object, it is recommended that the function should fail and report an [EINVAL] error. like, if you're gonna catch it, catch it properly. πŸ’…


πŸ“ FUTURE DIRECTIONS πŸ“

None.


🌟 SEE ALSO 🌟

  • pthread_attr_destroy()
  • pthread_attr_getinheritsched()
  • pthread_attr_getschedpolicy()
  • pthread_attr_getschedparam()
  • pthread_create()

and from the Base Definitions volume of POSIX.1‐2017: <pthread.h>, <sched.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 .


okay that's the whole page, you ate that bestie 🫢 this was IEEE/The Open Group, 2017, and we were reading PTHREAD_ATTR_GETSCOPE(3P) the entire time. mwah. πŸ’‹βœ¨

πŸ“¦ where this page comes from