PTHREAD...EDPOLICY(3POSIX)

πŸ’– PTHREAD_ATTR_GETSCHEDPOLICY, PTHREAD_ATTR_SETSCHEDPOLICY πŸ’–

okay bestie, welcome to the PTHREAD...EDPOLICY(3POSIX) page from the POSIX Programmer's Manual 🫢 this one is all about the schedpolicy attribute and honestly? she's lowkey iconic.


🌸 PROLOG 🌸

okay so first things first, real talk: this manual page is part of the POSIX Programmer's Manual. the Linux implementation of this interface may differ β€” so pls consult the corresponding Linux manual page for the deets on Linux behavior. or… the interface might not even be implemented on Linux at all 😭 not every platform shows up to the party.


✨ NAME ✨

pthread_attr_getschedpolicy, pthread_attr_setschedpolicy β€” get and set the schedpolicy attribute (REALTIME THREADS) πŸ”₯


πŸŽ€ SYNOPSIS πŸŽ€

#include <pthread.h>

int pthread_attr_getschedpolicy(const pthread_attr_t *restrict attr,
    int *restrict policy);
int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy);

πŸ’… DESCRIPTION πŸ’…

so like, pthread_attr_getschedpolicy() and pthread_attr_setschedpolicy() respectively shall get and set the schedpolicy attribute in the attr argument. one reads, one writes, they're a duo, they ate πŸ’–

the supported values of policy shall include SCHED_FIFO, SCHED_RR, and SCHED_OTHER, which are defined in the <sched.h> header. and here's the tea bestie: when threads executing with the scheduling policy SCHED_FIFO, SCHED_RR, or SCHED_SPORADIC are waiting on a mutex, they shall acquire the mutex in priority order when the mutex is unlocked. priority order, periodt. πŸ‘‘

⚠️ warning warning: the behavior is undefined if the value specified by the attr argument to pthread_attr_getschedpolicy() or pthread_attr_setschedpolicy() does not refer to an initialized thread attributes object. like, don't do that. uninitialized attr = chaos, no cap 😭

🌈 RETURN VALUE 🌈

if everything's slay: both pthread_attr_getschedpolicy() and pthread_attr_setschedpolicy() shall return zero ✨ otherwise, an error number shall be returned to indicate the error. zero = good vibes, nonzero = something's off.


πŸ’€ ERRORS πŸ’€

pthread_attr_setschedpolicy() shall fail if:

  • ENOTSUP β€” an attempt was made to set the attribute to an unsupported value. like girl, that value is not on the menu πŸ™ˆ

pthread_attr_setschedpolicy() may fail if:

  • EINVAL β€” the value of policy is not valid. not it. not the vibe. 🚫

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

the following sections are informative β€” so like, they're the bonus content, the director's commentary, the little extras 🎬


πŸ¦‹ EXAMPLES πŸ¦‹

None. yeah, bestie, there's literally nothing here. the void. the silence. πŸ’€


🧚 APPLICATION USAGE 🧚

okay so here's how you actually use this: after these attributes have been set, a thread can be created with the specified attributes using pthread_create(). cute, right? πŸŽ€

but important: using these routines does not affect the current running thread. like, you're not changing yourself, you're changing the blueprint for the next thread. main character stays main character, but the sequel gets new lore πŸ’…

for further details on thread scheduling attributes and their default settings, see Section 2.9.4, Thread Scheduling. iykyk πŸ“–


πŸ‘‘ RATIONALE πŸ‘‘

if an implementation detects that the value specified by the attr argument to pthread_attr_getschedpolicy() or pthread_attr_setschedpolicy() does not refer to an initialized thread attributes object, it is recommended that the function should fail and report an [EINVAL] error. so like, the standard is gently suggesting: bestie, just error out, it's the polite thing to do 🫢


⭐ FUTURE DIRECTIONS ⭐

None. nothing coming. the future is now, and the future is also empty. πŸ’–


🌸 SEE ALSO 🌸

  • pthread_attr_destroy()
  • pthread_attr_getscope()
  • pthread_attr_getinheritsched()
  • 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 bestie, you made it to the end, you're literally so smart πŸ† this was the IEEE/The Open Group, 2017 era of PTHREAD...EDPOLICY(3POSIX), and yes the version and date are right there, mwah, bye πŸ’‹πŸ’–βœ¨