pthread scheduling methods?

流过昼夜 提交于 2020-01-13 18:11:28

问题


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:


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.




回答2:


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).



来源:https://stackoverflow.com/questions/1362372/pthread-scheduling-methods

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!