Linux 什么';pthread_attr_setschedparam和pthread_setschedparam之间的区别是什么?

Linux 什么';pthread_attr_setschedparam和pthread_setschedparam之间的区别是什么?,linux,pthreads,posix,scheduling,Linux,Pthreads,Posix,Scheduling,pthread_attr_setschedparam和pthread_setschedparam之间有什么区别?我应该如何决定选择一个使用 命名令人困惑,但它们的用途不同 pthread_setschedparam用于设置线程的参数 pthread\u attr\u setschedparam用于设置线程参数的属性 也就是说 如果要设置特定属性,必须使用 pthread\u attr\u setschedparam 如果需要,请设置踏板的特定参数 要使用pthread\u setschedpa

pthread_attr_setschedparam和pthread_setschedparam之间有什么区别?我应该如何决定选择一个使用

命名令人困惑,但它们的用途不同


pthread_setschedparam
用于设置线程的参数

pthread\u attr\u setschedparam
用于设置线程参数的属性

也就是说

  • 如果要设置特定属性,必须使用
    pthread\u attr\u setschedparam
  • 如果需要,请设置踏板的特定参数 要使用
    pthread\u setschedparam

pthread_setschedparam()为现有线程设置调度程序策略和调度程序参数

pthread\u attr\u setschedparam()
pthread\u attr\u setschedpolicy()
分别为线程属性对象设置调度程序参数和调度程序策略(类型
pthread\u attr\u t
)。这将为随后使用该线程属性对象创建的任何新线程设置调度程序参数和调度程序策略(例如,您可以将线程属性对象作为
pthread\u create()
的第二个参数传递)


因此,要使用哪一个取决于您是要设置现有线程还是新线程的调度程序策略/参数。

阅读文档如何?不,这不对-您不必同时使用这两个策略/参数。根据是要更改线程还是线程属性对象的计划程序参数,可以使用其中一个或另一个。@caf您也可以同时使用这两个参数,对吗?首先使用thread属性对象,然后使用
pthread_setschedparam()