cc [ flag ... ] file ... -lsched [ library ... ] #include <schedctl.h>schedctl_t *schedctl_init(void);
These functions provide limited control over the scheduling of a lightweight process (LWP). They allow a running LWP to give a hint to the kernel that preemptions of that LWP should be avoided. The most likely use for these functions is to block preemption while holding a spinlock. Improper use of this facility, including attempts to block preemption for sustained periods of time, may result in reduced performance.
schedctl_init() initializes preemption control for the calling LWP and returns a pointer used to refer to the data. If schedctl_init() is called more than once by the same LWP, the most recently returned pointer is the only valid one.
schedctl_lookup() returns the currently allocated preemption control data associated with the calling LWP that was previously returned by schedctl_init() . This can be useful in programs where it is difficult to maintain local state for each LWP.
schedctl_exit() removes the preemption control data associated with the calling LWP.
schedctl_start() is a macro that gives a hint to the kernel scheduler that preemption should be avoided on the current LWP. The pointer passed to the macro must be the same as the pointer returned by the call to schedctl_init() by the current LWP. The behavior of the program when other values are passed is undefined.
schedctl_stop() is a macro that removes the hint that was set by schedctl_start() . As with schedctl_start() , the pointer passed to the macro must be the same as the pointer returned by the call to schedctl_init() by the current LWP.
schedctl_start() and schedctl_stop() are intended to be used to bracket short critical sections, such as the time spent holding a spinlock. Other uses, including the failure to call schedctl_stop() soon after calling schedctl_start() , may result in poor performance.
schedctl_init() returns a pointer to a schedctl_t structure if the initialization was successful, or NULL otherwise. schedctl_lookup() returns a pointer to a schedctl_t structure if the data for that LWP was found, or NULL otherwise.
Preemption control is intended for use by LWPs belonging to the time-sharing (TS) and interactive (IA) scheduling classes. If used by LWPs in other scheduling classes, such as real-time (RT), no errors will be returned but schedctl_start() and schedctl_stop() will not have any effect.
Use of preemption control by unbound threads in multithreaded applications (see thr_create(3THR) ) is not supported and will result in undefined behavior.
The data used for preemption control is not copied in the child of a fork(2) . Thus, if a process containing LWPs using preemption control calls fork , and the child does not immediately call exec(2) , each LWP in the child must call schedctl_init() again prior to any future uses of schedctl_start() and schedctl_stop() . Failure to do so will result in undefined behavior.