sched_setscheduler is for all threads or main thread?

柔情痞子 提交于 2019-12-06 01:51:32

You shall check (and set, if required) the scheduler inheritance attributes before creating any new thread.

int pthread_attr_getinheritsched(const pthread_attr_t *attr, int *inheritsched);

int pthread_attr_setinheritsched(pthread_attr_t *attr, int inheritsched);

The pthread_attr_getinheritsched() will store in the variable pointed by inheritsched one of two possible values:

  • PTHREAD_INHERIT_SCHED - Threads that are created using attr
    inherit scheduling attributes from the creating thread; the scheduling attributes in attr are ignored.

  • PTHREAD_EXPLICIT_SCHED - Threads that are created using attr take their scheduling attributes from the values specified by the attributes object.

If you want that every newly created thread inherits the scheduler attributes of the calling task, you should set PTHREAD_INHERIT_SCHED (if not already set).

Also note:

The default setting of the inherit-scheduler attribute in a newly initialized thread attributes object is PTHREAD_INHERIT_SCHED

References

$ man pthread_setschedparam
$ man pthread_attr_setinheritsched
  • (Blockquoted material was copied from parts of release 3.74 of the Linux man-pages project.)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!