|
ATTENTION:附加代碼鏈接:
http://blog.sina.com.cn/s/blog_6dc9e4cf0100xcvk.html
1. 線程屬性:
使用pthread_attr_t類型表示,我們需要對此結(jié)構(gòu)體進行初始化,
初始化后使用,使用后還要進行去除初始化!
pthread_attr_init:初始化
pthread_attr_destory:去除初始化
#include <pthread.h>
int pthread_attr_init(pthread_attr_t *attr);
int pthread_attr_destroy(pthread_attr_t *attr);
若成功返回0,若失敗返回-1。
pthread_attr_init之后,pthread_t結(jié)構(gòu)所包含的內(nèi)容就是操作系統(tǒng)實現(xiàn)
支持的線程所有屬性的默認值。
如果pthread_attr_init實現(xiàn)時為屬性對象分配了動態(tài)內(nèi)存空間,
pthread_attr_destroy還會用無效的值初始化屬性對象,因此如果經(jīng)
pthread_attr_destroy去除初始化之后的pthread_attr_t結(jié)構(gòu)被
pthread_create函數(shù)調(diào)用,將會導(dǎo)致其返回錯誤。
線程屬性結(jié)構(gòu)如下:
typedef struct
|