PTHREAD...GETSCOPE(3POSIX)

πŸ’– PTHREAD_ATTR_GETSCOPE, PTHREAD_ATTR_SETSCOPE β€” the POSIX girlies πŸ’–

okay so bestie, welcome to the PTHREAD...GETSCOPE(3POSIX) page, straight outta the POSIX Programmer's Manual. it's giving realtime threads, it's giving attribute objects, it's giving contentionscope ✨


🌸 PROLOG 🌸

so like, this manual page is part of the POSIX Programmer's Manual. but lowkey a heads up: the Linux implementation of this interface may differ β€” so consult the corresponding Linux manual page for the deets on Linux behavior. or honestly? the interface might not even be implemented on Linux at all. πŸ™ˆ iykyk.


✨ NAME ✨

pthread_attr_getscope, pthread_attr_setscope β€” get and set the contentionscope attribute πŸ’…

(REALTIME THREADS, no cap 🫢)


πŸŽ€ 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 pthread_attr_getscope() and pthread_attr_setscope() respectively shall get and set the contentionscope attribute inside the attr object. that's it, that's the job. πŸ’–

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.

⚠️ okay important: 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. so like… initialize ur attrs, bestie. don't be that girl. 😭

🌈 RETURN VALUE 🌈

if it slays (i.e. successful), pthread_attr_getscope() and pthread_attr_setscope() shall return zero. otherwise an error number shall be returned to indicate the error. no in-between. 🫢


πŸ’œ ERRORS πŸ’œ

pthread_attr_setscope() β€” shall fail if:

  • ENOTSUP β€” an attempt was made to set the attribute to an unsupported value. not on this system's watch πŸ’€

pthread_attr_setscope() β€” may fail if:

  • EINVAL β€” the value of contentionscope is not valid.

and also, huge: these functions shall not return an error code of [EINTR]. nope. never. don't even ask. ✨

the following sections are informative. (casual. low stakes. we're just chatting.)


πŸ“ EXAMPLES πŸ“

None.

like literally none. nothing. empty. the void. πŸ•³οΈ


🧚 APPLICATION USAGE 🧚

so once these attributes have been set, a thread can be created with the specified attributes using pthread_create(). cute, right? πŸ‘‘

and listen β€” using these routines does not affect the current running thread. so don't expect ur own vibe to shift. πŸ™ˆ

see Section 2.9.4, Thread Scheduling for further details on thread scheduling attributes and their default settings. it's giving required reading, fr fr. πŸ“š


πŸ‘‘ 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, that's the polite thing to do. πŸ’…


⭐ FUTURE DIRECTIONS ⭐

None.

(the future? empty. iconic behavior honestly. ✨)


πŸ’… 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 bye bestie, this was IEEE/The Open Group, 2017 β€” PTHREAD...GETSCOPE(3POSIX), signing off πŸŽ€βœ¨πŸ’–