PTHREAD_SCHEDPARAM(3)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1, nixpkgs unstable

πŸ’… PTHREAD_SCHEDPARAM(3) β€” thread scheduling parameter manipulation, bestie edition

okay so this is a page from the Library Functions Manual and honestly? it's giving "let me control exactly how your thread gets its turn on the CPU." We're talking pthread_setschedparam and pthread_getschedparam β€” the setter and the getter. iconic duo, no cap πŸŽ€


πŸ“š LIBRARY

POSIX Threads Library β€” that's libpthread, and you link it with -lpthread. periodt.


✨ SYNOPSIS ✨

#include <pthread.h>

int
pthread_setschedparam(pthread_t thread, int policy,
    const struct sched_param *param);

int
pthread_getschedparam(pthread_t thread, int *restrict policy,
    struct sched_param *restrict param);

πŸ¦‹ DESCRIPTION πŸ¦‹

So pthread_setschedparam() and pthread_getschedparam() set and get the scheduling parameters of individual threads. Like, per-thread vibes. Not the whole process, bestie β€” one thread at a time πŸ’…

The scheduling policy for a thread can be one of these three:

  • SCHED_FIFO β€” first in, first out 🌈
  • SCHED_RR β€” round-robin πŸŽ€
  • SCHED_OTHER β€” timesharing ⭐

And the valid thread priorities β€” those you access via param->sched_priority β€” have to be within the range returned by the sched_get_priority_min(2) and sched_get_priority_max(2) system calls. That's the range, okay? don't go outside it πŸ™ˆ


🫢 RETURN VALUES 🫢

If everything's slaying, these functions return 0. Otherwise an error number comes back to tell you what went wrong. that's it, that's the whole thing.


πŸ’€ ERRORS πŸ’€

So pthread_setschedparam() will fail if:

  • [EINVAL] β€” invalid value for policy. (you gave it a policy that isn't a policy, bestie 😭)
  • [ENOTSUP] β€” invalid value for scheduling parameters.
  • [EPERM] β€” the calling thread does not have sufficient privilege to perform the operation. (no permission, no party πŸ”₯)
  • [ESRCH] β€” non-existent thread thread.

And pthread_getschedparam() will fail if:

  • [ESRCH] β€” non-existent thread thread. (same energy, thread literally not found)

πŸ‘‘ SEE ALSO πŸ‘‘


🌸 STANDARDS 🌸

The pthread_setschedparam() and pthread_getschedparam() functions conform to Version 2 of the Single UNIX Specification (β€œSUSv2”). certified official, iykyk ✨


ngl the whole thing is a two-function page and it still ate. read the min/max priority calls before you go setting anything, fr fr 🧚

mwah πŸ’œ this page came from Debian, dated October 17, 2022 β€” and that's the whole manual page, bestie, see you in the next one πŸŽ€

πŸ“¦ where this page comes from