PreviousNext

Scheduling Policy Attribute

The scheduling policy attribute describes the overall scheduling policy of the threads in your application. A thread has one of the following scheduling policies:

· SCHED_FIFO (First In, First Out)

The highest-priority thread runs until it blocks. If there is more than one thread with the same priority, and that priority is the highest among other threads, the first thread to begin running continues until it blocks.

· SCHED_RR (Round Robin)

The highest-priority thread runs until it blocks; however, threads of equal priority, if that priority is the highest among other threads, are timesliced. (Timeslicing is a mechanism that ensures that every thread is allowed time to execute by preempting running threads at fixed intervals.)

· SCHED_OTHER, SCHED_FG_NP (Default)

All threads are timesliced. SCHED_OTHER and SCHED_FG_NP do the same thing; however, SCHED_FG_NP is simply more precise terminology. The FG stands for foreground and the NP for new primitive. All threads running under the SCHED_OTHER and SCHED_FG_NP policy, regardless of priority, receive some scheduling. Therefore, no thread is completely denied execution time. However, SCHED_OTHER and SCHED_FG_NP threads can be denied execution time by SCHED_FIFO or SCHED_RR threads.

· SCHED_BG_NP (Background)

Like SCHED_OTHER and SCHED_FG_NP, SCHED_BG_NP ensures that all threads, regardless of priority, receive some scheduling. However, SCHED_BG_NP can be denied execution by the SCHED_FIFO or SCHED_RR policies. The BG stands for background.

The following two methods are used to set the scheduling policy attribute:

· Set the scheduling policy attribute in the attributes object, which establishes the scheduling policy of a new thread when it is created. To do this, call the pthread_attr_setsched( ) routine.

· Change the scheduling policy of an existing thread (and, at the same time, the scheduling priority) by calling the pthread_setscheduler( ) routine.

Thread Scheduling describes and shows the effect of scheduling policy on thread scheduling.