PTHREAD_A...CHEDPOLICY(3P)
โจ pthread_attr_getschedpolicy, pthread_attr_setschedpolicy โจ
okay bestie, so this is a page from the POSIX Programmer's Manual (section 3P, we love a section code), and it's all about getting and setting the schedpolicy attribute. REALTIME THREADS edition, periodt. ๐งต๐
๐ธ PROLOG ๐ธ
okay real talk before we start: this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (so if you're on Linux, go consult the corresponding Linux manual page for the deets on Linux behavior), or honestly the interface may not be implemented on Linux at all. ๐ not me being a POSIX purist about it.
๐ NAME ๐
pthread_attr_getschedpolicy, pthread_attr_setschedpolicy โ get and set the schedpolicy attribute (REALTIME THREADS). yes bestie it's giving "get and set", it's giving duality. ๐ฆ
๐ 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);
look at those restrict qualifiers, they're so iconic, they're literally promising nobody else is touching that memory. ๐
๐ DESCRIPTION ๐
so. pthread_attr_getschedpolicy() and pthread_attr_setschedpolicy() shall (POSIX said what it said) respectively get and set the schedpolicy attribute in the attr argument. that's the whole vibe. โจ
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 part that's actually highkey important: 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!! the VIP line!! ๐
โ ๏ธ okay listen. the behavior is undefined if the value specified by theattrargument topthread_attr_getschedpolicy()orpthread_attr_setschedpolicy()does not refer to an initialized thread attributes object. undefined behavior is not cute, it's not a slay, it's a "your program is now a haunted house" situation. initialize your attrs, bestie. ๐ซถ
๐ RETURN VALUE ๐
if it slays: pthread_attr_getschedpolicy() and pthread_attr_setschedpolicy() shall return zero. zero = the win. ๐
if it doesn't: an error number shall be returned to indicate the error. no cap.
๐จ ERRORS ๐จ
the pthread_attr_setschedpolicy() function shall fail if:
ENOTSUPโ an attempt was made to set the attribute to an unsupported value. babe. it's not supported. it said no. ๐
the pthread_attr_setschedpolicy() function may fail if:
EINVALโ the value ofpolicyis not valid. you handed it something it does not recognize. that's not a valid policy, that's a cry for help. ๐ญ
and then the note: these functions shall not return an error code of [EINTR]. nope, not a thing here. ๐
oh also: the following sections are informative. iykyk โ informative means "flavor text, not normative requirements". ๐โจ
๐ EXAMPLES ๐
None.
(i'm not being lazy, that's literally what it says. the manpage said "None." and i respect it for that. ๐)
๐ผ APPLICATION USAGE ๐ผ
after these attributes have been set, a thread can be created with the specified attributes using pthread_create(). ๐งต
and here's a little โจ boundary setting โจ moment: using these routines does not affect the current running thread. the current thread is unbothered. the current thread is thriving. the current thread is not taking questions. ๐ซถ
see Section 2.9.4, Thread Scheduling for further details on thread scheduling attributes and their default settings. go read it, it's giving required reading for the scheduling girlies. ๐
๐ญ 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. recommended! like, we're suggesting it. we think it would be nice. ๐ฅบ
๐ฎ FUTURE DIRECTIONS ๐ฎ
None.
(future: still none. the future is stable. we love stability. ๐)
๐ 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>. ๐
๐ 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. (referee = final boss = the one who decides. respect it. ๐) 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. ๐
๐ซถ cute little sign-off ๐ซถ
this whole thing was brought to you by IEEE/The Open Group, 2017, filed under PTHREAD_A...CHEDPOLICY(3P) โ yeah the title got truncated in the middle, that's just how it is, the manpage said "a...chedpolicy" and honestly? iconic. ๐โจ
go forth and set your schedpolicy responsibly. mwah. ๐ ๐
๐ฆ 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