views:

684

answers:

2

With no explicit scheduling, pthreads are scheduled to run by the kernel in a random manner.

Are there any scheduling methods defined in the pthread library for the same such as priorities?

+1  A: 

The priority of a thread is specified as a delta which is added to the priority of the process. Changing the priority of the process, effects the priority of all of the threads within that process. The default priority for a thread is DEFAULT_PRIO_NP, which is no change from the process priority.

These Pthread APIs support only a scheduling policy of SCHED_OTHER.

  1. pthread_setschedparam (SCHED_OTHERonly supported)
  2. pthread_getschedparam
  3. pthread_attr_setschedparam
  4. pthread_attr_getschedparam

An AS/400 thread competes for scheduling resources against other threads in the system, not solely against other threads in the process. The scheduler is a delay cost scheduler based on several delay cost curves (priority ranges). The Posix standard and the Single Unix Specification refers to this as scheduling scope and scheduling policy, which on this implementation cannot be changed from the default of SCHED_OTHER.

Vaibhav
A: 

It can be controlled somewhat. For threads at the same priority, the pthreads standard specifies the choices of FIFO (thread runs until it blocks or exits), Round Robin (thread runs for a fixed amount of time), or the default "Other". The only one that is required by the standard is "Other" whose behavior is implementation dependent but usually a combo of FIFO and Round Robin (eg, thread runs until it blocks, exits, or timeslice is used up whichever happens first).

Apprentice Queue