pthread_at...schedparam(3)
π pthread_at...schedparam(3) π
okay bestie, welcome to the pthread_at...schedparam page from the Library Functions Manual β¨ this is the one where we set and get the scheduling parameter attributes hiding inside a thread attributes object. buckle up, it's lowkey iconic π
πΈ NAME πΈ
pthread_attr_setschedparam</p>, pthread_attr_getschedparam</p> β set/get scheduling parameter attributes in thread attributes object π¦
π LIBRARY π
POSIX threads library (libpthread, -lpthread) π
β¨ SYNOPSIS β¨
#include <pthread.h>
int pthread_attr_setschedparam(pthread_attr_t *restrict attr,
const struct sched_param *restrict param);
int pthread_attr_getschedparam(const pthread_attr_t *restrict attr,
struct sched_param *restrict param);
π«Ά DESCRIPTION π«Ά
so like, pthread_attr_setschedparam() sets the scheduling parameter attributes of the thread attributes object that attr points at, copying in the values from the buffer that param points to. and these attributes? they literally decide what scheduling parameters a thread gets when it's created using that thread attributes object attr. main character energy fr π«
and pthread_attr_getschedparam() does the other direction: it hands you back the scheduling parameter attributes of the thread attributes object attr, dropping them into the buffer that param points to. giving β¨inspectβ¨ π
scheduling parameters live in this lil structure right here:
struct sched_param {
int sched_priority; /* Scheduling priority */
};
as you can see, there's exactly one scheduling parameter supported. that's it, that's the whole vibe π if you wanna know the permitted ranges for scheduling priorities in each scheduling policy, go look at sched(7) β she has the deets π
β οΈ okay important one: for the setting thatpthread_attr_setschedparam()made to actually do anything when you callpthread_create(3), you have to usepthread_attr_setinheritsched(3)to set the inherit-scheduler attribute of the attributes objectattrtoPTHREAD_EXPLICIT_SCHED. no cap, otherwise it's giving nothing π
π RETURN VALUE π
on success these functions return 0. on error they return a nonzero error number. that's it bestie, that's the whole contract π
π ERRORS π
pthread_attr_setschedparam() can fail with this one:
EINVALβ the priority specified inparamdoes not make sense for the current scheduling policy ofattr. like, it's not valid here, girl, read the room π«
also, POSIX.1 documents an ENOTSUP error for pthread_attr_setschedparam() too. but on Linux this value is never returned π (still tho, portable and future-proof applications should handle that error return value anyway β be that girl who's prepared π«‘)
π ATTRIBUTES π
for an explanation of the terms used in this section, see attributes(7).
pthread_attr_setschedparam(),pthread_attr_getschedparam()β Thread safety: MT-Safe π₯
β STANDARDS β
POSIX.1-2008. periodt β
π°οΈ HISTORY π°οΈ
POSIX.1-2001. glibc 2.0. she's been around a minute and she ate π
π NOTES π
see pthread_attr_setschedpolicy(3) for a list of the thread scheduling policies supported on Linux π§
π EXAMPLES π
see pthread_setschedparam(3). go look bestie π
π SEE ALSO π
sched_get_priority_min(2)pthread_attr_init(3)pthread_attr_setinheritsched(3)pthread_attr_setschedpolicy(3)pthread_create(3)pthread_setschedparam(3)pthread_setschedprio(3)pthreads(7)sched(7)
this page is brought to you by Linux man-pages 6.20, dated 2025-05-17 π¦ mwah, tysm for reading, go schedule something responsibly π β¨
π¦ where this page comes from
- 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 6.20
- π the page's license: Linux-man-pages-copyleft
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms