PTHREAD_ATTR_SETSCHEDPOLICY(3)

πŸ’– pthread_at...schedpolicy(3) πŸ’–

okay bestie, so this is the Library Functions Manual page for the whole pthread_attr_setschedpolicy / pthread_attr_getschedpolicy situation, and it lives in the POSIX threads library, aka libpthread, which you link with -lpthread. yes it's giving thread girlboss energy. let's go 🧚


✨ NAME ✨

pthread_attr_setschedpolicy, pthread_attr_getschedpolicy β€” set/get scheduling policy attribute in thread attributes object πŸŽ€


🌸 LIBRARY 🌸

POSIX threads library (libpthread, -lpthread)


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <pthread.h>

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

πŸ’… DESCRIPTION πŸ’…

so pthread_attr_setschedpolicy() sets the scheduling policy attribute of the thread attributes object that attr points at, and it sets it to whatever's in policy. and like, this attribute is the thing that determines the scheduling policy of a thread that gets created using that attr thread attributes object. main character behaviour honestly ✨

the values you're allowed to pass for policy are SCHED_FIFO, SCHED_RR, and SCHED_OTHER, and the semantics for all of them are described over in sched(7). no cap.

then pthread_attr_getschedpolicy() just hands you back the scheduling policy attribute of the thread attributes object attr, dropped into the buffer that policy points to. cute, right? 🫢

and hmm, important lil plot twist: for the policy you set with pthread_attr_setschedpolicy() to actually have effect when you call pthread_create(3), you (the caller, yes you) must use pthread_attr_setinheritsched(3) to set the inherit-scheduler attribute of the attributes object attr to PTHREAD_EXPLICIT_SCHED. like, otherwise it does nothing and you'll be so confused. it's giving gotcha. 😭


⭐ RETURN VALUE ⭐

on success these functions return 0. on error they return a nonzero error number. periodt.


πŸ’€ ERRORS πŸ’€

pthread_attr_setschedpolicy() can fail with this error:

  • EINVAL β€” Invalid value in policy.

also, POSIX.1 documents an optional ENOTSUP error ("attempt was made to set the attribute to an unsupported value") for pthread_attr_setschedpolicy(). so like, it might show up. iykyk. πŸ™ˆ


πŸ‘‘ ATTRIBUTES πŸ‘‘

for an explanation of the terms used in this section, see attributes(7).

  • Interface: pthread_attr_setschedpolicy(), pthread_attr_getschedpolicy()
  • Attribute: Thread safety
  • Value: MT-Safe

that's a whole MT-Safe glow-up, obsessed 🌈


πŸŽ€ STANDARDS πŸŽ€

POSIX.1-2008.


🌸 HISTORY 🌸

glibc 2.0. POSIX.1-2001. ancient queen behaviour, respectfully πŸ’œ


πŸ“ EXAMPLES πŸ“

See pthread_setschedparam(3).


πŸ”₯ SEE ALSO πŸ”₯


and that's a wrap on the pthread_at...schedpolicy(3) page bestie πŸ’– this whole thing comes from Linux man-pages 6.20, dated 2025-05-17. slay, 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