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 that pthread_attr_setschedparam() made to actually do anything when you call pthread_create(3), you have to use pthread_attr_setinheritsched(3) to set the inherit-scheduler attribute of the attributes object attr to PTHREAD_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 in param does not make sense for the current scheduling policy of attr. 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 πŸ‘‘


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