![[Return to Bookshelf]](BOOKSHELF.GIF) 
![[Contents]](TOC.GIF) 
![[Previous Section]](PREV.GIF) 
![[Next Section]](NEXT.GIF) 
![[Index]](INDEX.GIF) 
![[Help]](HELP.GIF) 
The scheduling policy attribute describes how the thread
is scheduled for execution relative to the other threads in the
program. A thread has one of the following scheduling policies:
   - SCHED_FIFO (first-in/first-out (FIFO))-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. If a thread with this policy becomes ready, and
   it has a higher priority than the currently running thread, then
   it preempts the current thread and begins running immediately.
   
- SCHED_RR (round-robin (RR))-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.) If a thread with this policy becomes
   ready, and it has a higher priority than the currently running
   thread, then it preempts the current thread and begins running
   immediately.
   
- SCHED_FG_NP (also known as SCHED_OTHER) (Default)-All
   threads are timesliced. Under this policy, all threads receive
   some scheduling regardless of priority. Therefore, no thread
   is completely denied execution time. Nevertheless, higher
   priority threads receive more execution time than lower priority
   threads. Threads with the default scheduling policy can be denied
   execution time by FIFO or RR threads.
   
- SCHED_BG_NP (Background)-Like the default (throughput)
   scheduling policy, this policy ensures that all threads,
   regardless of priority, receive some scheduling. However,
   background threads can be denied execution time by FIFO or RR
   threads, and receive less execution time than default policy
   threads.
   
Note that only SCHED_FIFO and SCHED_RR are portable. The
name SCHED_OTHER is also portable, but its behavior may
vary. For example, on some platforms it could be identical to SCHED_
FIFO or SCHED_RR. The other policies are DECthreads extensions. You
can use either of the following methods 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_
   setschedpolicy routine. This allows the creator of a thread to
   establish the created thread's initial scheduling policy. Note
   that this value is used only if the attributes object is set so
   that the created thread does not inherit its priority from the
   creating thread. Inheriting priority is the default behavior.
   
- Change the scheduling policy of an existing thread
   (and, at the same time, the scheduling parameters) by calling
   the pthread_setschedparam routine. This has no effect on an
   attributes object.
   
Section 2.7 describes and shows the effect of
the scheduling policy on thread scheduling.
![[Return to Bookshelf]](BOOKSHELF.GIF) 
![[Contents]](TOC.GIF) 
![[Previous Section]](PREV.GIF) 
![[Next Section]](NEXT.GIF) 
![[Index]](INDEX.GIF) 
![[Help]](HELP.GIF)