PTHREAD...EDPARAM(3POSIX)

๐Ÿ’… PTHREAD...EDPARAM(3POSIX) โ€” the POSIX Programmer's Manual, bestie edition ๐ŸŽ€

okay so first things first, real talk: this page lives in the POSIX Programmer's Manual, and there's a little โœจdisclaimerโœจ you need to know before we get into it.

โš ๏ธ Heads up babes: this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (so go check the corresponding Linux manual page for the deets on Linux behavior), or honestly the interface may not be implemented on Linux at all. Not every baddie is available everywhere, iykyk. ๐Ÿ’€

โœจ NAME โœจ

pthread_attr_getschedparam, pthread_attr_setschedparam โ€” get and set the schedparam attribute ๐ŸŽ€


๐ŸŒธ SYNOPSIS ๐ŸŒธ

#include <pthread.h>

int pthread_attr_getschedparam(const pthread_attr_t *restrict attr,
    struct sched_param *restrict param);
int pthread_attr_setschedparam(pthread_attr_t *restrict attr,
    const struct sched_param *restrict param);

๐Ÿ’– DESCRIPTION ๐Ÿ’–

so basically, pthread_attr_getschedparam() and pthread_attr_setschedparam() do exactly what it says on the tin, bestie โ€” they get and set the scheduling parameter attributes inside that attr argument. ๐Ÿ“ฅ๐Ÿ“ค

The contents of the param structure are defined in the <sched.h> header. For the SCHED_FIFO and SCHED_RR policies, the only required member of param is sched_priority. That's it, that's the whole requirement. simple. iconic. โœจ

For the SCHED_SPORADIC policy though? Now we're in our main character era, and the required members of the param structure are:

  • sched_priority
  • sched_ss_low_priority
  • sched_ss_repl_period
  • sched_ss_init_budget
  • sched_ss_max_repl

and there are rules, okay? listen up ๐Ÿซถ

  • The specified sched_ss_repl_period must be greater than or equal to the specified sched_ss_init_budget for the function to succeed. If it is not โ€” the function shall fail. no cap.
  • The value of sched_ss_max_repl shall be within the inclusive range [1,{SS_REPL_MAX}] for the function to succeed. If not โ€” yeah, the function shall fail. ๐Ÿ˜ญ
  • It is unspecified whether the sched_ss_repl_period and sched_ss_init_budget values are stored exactly as provided by this function, or are rounded to align with the resolution of the clock being used. so don't come for us if it's a little off-grid. ๐Ÿ•
๐Ÿ’€ undefined behavior alert ๐Ÿ’€ The behavior is undefined if the value specified by the attr argument to pthread_attr_getschedparam() or pthread_attr_setschedparam() does not refer to an initialized thread attributes object. Like, don't do that. Please. ๐Ÿ™ˆ

๐Ÿ‘‘ RETURN VALUE ๐Ÿ‘‘

If it's giving success? Both pthread_attr_getschedparam() and pthread_attr_setschedparam() shall return zero. ๐ŸŒŸ

Otherwise? An error number shall be returned to indicate the error. that's it, that's the vibe check. โœ…โŒ


๐Ÿ”ฅ ERRORS ๐Ÿ”ฅ

The pthread_attr_setschedparam() function shall fail if:

  • ENOTSUP โ€” An attempt was made to set the attribute to an unsupported value. ๐Ÿ˜ค not supported, not the vibe.

The pthread_attr_setschedparam() function may fail if:

  • EINVAL โ€” The value of param is not valid. ๐Ÿšซ
๐Ÿ›‘ also super important: these functions shall not return an error code of [EINTR]. like, that one's just not happening, periodt.

The following sections are informative. ๐Ÿ“ (yes girl, we're in the informational zone now)


๐ŸŒˆ EXAMPLES ๐ŸŒˆ

None. ๐Ÿ˜Œ nothing to see here, moving on bestie.


๐Ÿฆ‹ APPLICATION USAGE ๐Ÿฆ‹

After these attributes have been set, a thread can be created with the specified attributes using pthread_create(). ๐Ÿงตโœจ

And real quick โ€” using these routines does not affect the current running thread. so your main character stays exactly as she is, no side effects, we love to see it. ๐Ÿ’…


๐Ÿ’œ RATIONALE ๐Ÿ’œ

If an implementation detects that the value specified by the attr argument to pthread_attr_getschedparam() or pthread_attr_setschedparam() does not refer to an initialized thread attributes object, it is recommended that the function should fail and report an [EINVAL] error. like, just be honest about it, y'know? ๐Ÿซถ


โญ FUTURE DIRECTIONS โญ

None. ๐Ÿ”ฎ the future is... empty. slay.


๐ŸŽ€ SEE ALSO ๐ŸŽ€

  • pthread_attr_destroy()
  • pthread_attr_getscope()
  • pthread_attr_getinheritsched()
  • pthread_attr_getschedpolicy()
  • pthread_create()

The Base Definitions volume of POSIX.1โ€2017, <pthread.h>, <sched.h> ๐Ÿ“š


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. 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. ๐Ÿ›


and that's the whole page, bestie!! this one came from IEEE/The Open Group, 2017 (the PTHREAD...EDPARAM(3POSIX) page, if you're keeping track ๐ŸŽ€). go forth and schedule your threads responsibly, mwah ๐Ÿ’‹โœจ๐Ÿฆ‹

๐Ÿ“ฆ where this page comes from