初始化/销毁线程属性
int pthread_attr_init(pthread_attr_t *attr);int pthread_attr_destroy(pthread_attr_t *attr);
线程分离属性
int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate);int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate);
参数说明:
Thefollowingvaluesmaybespecifiedindetachstate:
PTHREAD_CREATE_DETACHED
Threadsthatarecreatedusingattrwillbecreatedinadetachedstate.
PTHREAD_CREATE_JOINABLE
Threadsthatarecreatedusingattrwillbecreatedinajoinablestate.
Thedefaultsettingofthedetachstateattributeinanewlyinitialized
threadattributesobjectisPTHREAD_CREATE_JOINABLE.
Thepthread_attr_getdetachstate()returnsthedetachstateattributeofthe
threadattributesobjectattrinthebufferpointedtobydetachstate.
线程栈大小
int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize);int pthread_attr_getstacksize(pthread_attr_t *attr, size_t *stacksize);
DESCRIPTION
Thepthread_attr_setstacksize()functionsetsthestacksizeattribute
ofthethreadattributesobjectreferredtobyattrtothevaluespecified
instacksize.(一般情况下该值我们设置为0,使用系统默认设置的线程栈大小,否则可能会引起程序的可移植性的问题) Thestacksizeattributedeterminestheminimumsize(inbytes)thatwill
beallocatedforthreadscreatedusingthethreadattributesobjectattr.
Thepthread_attr_getstacksize()functionreturnsthestacksizeattributeof
thethreadattributesobjectreferredtobyattrinthebufferpointedtobystacksize.
线程栈溢出保护区大小
int pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize);int pthread_attr_getguardsize(pthread_attr_t *attr, size_t *guardsize);
线程竞争范围(进程范围内的竞争 or 系统范围内的竞争)
int pthread_attr_getscope(const pthread_attr_t *attr,int *contentionscope);int pthread_attr_setscope(pthread_attr_t *attr, int contentionscope);
contentionscope说明:
PTHREAD_SCOPE_SYSTEM
Thethreadcompetesforresourceswithallotherthreadsinallprocesseson
thesystemthatareinthesameschedulingallocationdomain(agroupofoneormoreprocessors).
PTHREAD_SCOPE_SYSTEMthreadsarescheduledrelativetooneanotheraccordingtotheir
schedulingpolicyandpriority.
PTHREAD_SCOPE_PROCESS
Thethreadcompetesforresourceswithallotherthreadsinthesameprocessthatwere
also created with the PTHREAD_SCOPE_PROCESS contention scope.
PTHREAD_SCOPE_PROCESSthreadsarescheduledrelativetootherthreadsintheprocess
accordingtotheirschedulingpolicyandpriority.POSIX.1-2001leavesitunspecifiedhowthesethreadscontendwithotherthreadsinotherprocess
onthesystemorwithotherthreadsinthesameprocessthatwerecreatedwiththe
PTHREAD_SCOPE_SYSTEMcontentionscope.
线程调度策略
int pthread_attr_getschedpolicy(const pthread_attr_t *attr, int *policy);int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy);
DESCRIPTION
Thepthread_attr_setschedpolicy()functionsetstheschedulingpolicyattributeofthethread
可以有一个人陪着你,也可以你一个人,总之那一刻,