6.7.4 设置线程的竞争范围

2013-10-07 12:59:09 · 作者: · 浏览: 69

6.7.4  设置线程的竞争范围

线程的竞争范围决定了线程同哪些其他线程竞争处理器的使用。竞争范围是由线程属性对象设置的。

调用形式

  1. #include <pthread.h> 
  2.                 
  3. int pthread_attr_setscope(pthread_attr_t *attr, int contentionscope);  
  4. int pthread_attr_getscope(const pthread_attr_t *restrict attr,  
  5.                          int *restrict contentionscope); 

pthread_attr_setscope( )设置由attr指定的线程属性对象的竞争范围属性。线程属性对象的竞争范围会设置为保存在contentionscope中的值。contentionscope可以为以下值。

PTHREAD_SCOPE_SYSTEM:系统调度竞争范围

PTHREAD_SCOPE_PROCESS:进程调度竞争范围

系统竞争范围意味线程同系统范围内其他进程的线程进行竞争。pthread_attr_getscope( )从attr指定的线程属性对象返回竞争范围属性。如果函数成功,则返回线程属性对象的竞争范围,并保存到contentionscope中。这两个函数如果成功则返回0,否则返回错误号。