2.删除属性对象pthread_attr_destroy
#include
int pthread_attr_destroy(pthread_attr_t *attr);
返回值:函数成功返回0;任何其他返回值都表示错误
用来删除属性对象占用的内存。调用这个函数后,相应的属性对象无效。
3.设置分离状态pthread_attr_setdetachstate
#include
int pthread_attr_setdetachstate(pthread_attr_t *attr,
int detachstate);
返回值:函数成功返回0;任何其他返回值都表示错误
设置分离状态。参数detachstate的值为:PTHREAD_CREATE_DETACHED、PTHREAD_CREATE_JOINABLE。
注意:如果没有有效的同步措施,一个刚创建的分离线程有可能在pthread_create()函数返回之前就终止了,而它的线程标识符则被另一个新线程所使用。
4.获取分离状态pthread_attr_getdetachstate
#include
int pthread_attr_getdetachstate(pthread_attr_t *attr,
int *detachstate);
返回值:函数成功返回0;任何其他返回值都表示错误
取线程分离状态:分离的或是非分离的。
7.设置域pthread_attr_setscope
#include
int pthread_attr_setscope(pthread_attr_t *tattr, int scope);
返回值:函数成功返回0;任何其他返回值都表示错误
设置域。指定将来创建的线程是绑定(PTHREAD_SCOPE_SYSTEM)的还是非绑定的(PTHREAD_SCOPE_PROCESS)。
在一个进程中可以同时有这两种不同类型的线程。
8.获取域pthread_attr_getscope
#include
int pthread_attr_getscope(pthread_attr_t *tattr, int *scope);
返回值:函数成功返回0;任何其他返回值都表示错误
取线程的域(绑定的或是非绑定的)。
9.设置并发级别pthread_setconcurrency
#include
int pthread_setconcurrency(int new_level);
返回值:函数成功返回0;任何其他返回值都表示错误
设置线程并发级别。
在一个进程中,可能需要多个非绑定的线程被同时激活(即绑定到LWP上参与核心的并发调度)。缺省情况下,线程库保证有足够多的线程处在激活状态下以确保进程的运行。尽管这样可以节省系统资源,但并不一定能得到最有效的并发性。
该函数允许一个应用程序通知线程库它所需要的并行级别(即同一时刻最多可以有多少个非绑定线程处在激活状态下)。但只是通知系统它所需要的并发级别,系统将它作为一种提示,而不是命令。
如果参数new_level的值为0,并行级别将保持不变,就像该函数从来没有被调用过。
10.获取并发级别pthread_getconcurrency
#include
int pthread_getconcurrency(void);
取线程并发级别。
返回原来由pthread_setconcurrency()函数设置的值。如果在这之前没有调用过pthread_setconcurrency()函数,pthread_getconcurrency()函数将返回0,这表示由线程库维护并发级别。
11.设置调度策略pthread_attr_setschedpolicy
#include
int pthread_attr_setschedpolicy(pthread_attr_t *tattr,
int policy);
返回值:函数成功返回0;任何其他返回值都表示错误
设置调度策略。
POSIX标准定义的调度策略有:SCHED_FIFO(先入先出)、SCHED_RR(循环)、SCHED_OTHER(由不同版本的POSIX线程库定义的缺省调度策略)。
12.获取调度策略pthread_attr_getschedpolicy
#include
int pthread_attr_getschedpolicy(pthread_attr_t *tattr,
int *policy);
返回值:函数成功返回0;任何其他返回值都表示错误
取调度策略。
13.设置继承调度策略pthread_attr_setinheritsched
#include
int pthread_attr_setinheritsched(pthread_attr_t *tattr,
int inherit);
返回值:函数成功返回0;任何其他返回值都表示错误
设置继承调度策略。
如果inherit参数的值为PTHREAD_INHERIT_SCHED(缺省值),那么用这个属性对象创建的线程都将具有父线程的调度策略(属
性对象中的调度策略参数将不起作用)。如果inherit参数的值为PTHREAD_EXPLICIT_SCHED,那么用这个属性对象创建线程时,线程
的调度策略和父线程无关,属性对象中的调度策略参数将起作用。
14.获取继承调度策略pthread_attr_getinheritsched
#include
int pthread_attr_getinheritsched(pthread_attr_t *tattr,
int *inherit);
返回值:函数成功返回0;任何其他返回值都表示错误
获取继承调度策略。