📄 pthread.3
字号:
function is used to destroy a thread attributes object.An implementation may cause\&\fI\fIpthread_attr_destroy()\fI\fRto set\&\fIattr\fRto an implementation-dependent invalid value.The behaviour of using the attribute after it has been destroyed is undefined..SH "RETURN VALUE".IX Header "RETURN VALUE"Upon successful completion,\&\fI\fIpthread_attr_init()\fI\fRand\&\fI\fIpthread_attr_destroy()\fI\fRreturn a value of 0.Otherwise, an error number is returned to indicate the error..SH "ERRORS".IX Header "ERRORS"The\&\fI\fIpthread_attr_init()\fI\fRfunction will fail if:.IP "[\s-1ENOMEM\s0]" 4.IX Item "[ENOMEM]"Insufficient memory exists to initialise the thread attributes object..PPThese functions will not return an error code of [\s-1EINTR\s0]..SH "EXAMPLES".IX Header "EXAMPLES"None..SH "APPLICATION USAGE".IX Header "APPLICATION USAGE"None..SH "FUTURE DIRECTIONS".IX Header "FUTURE DIRECTIONS"None..SH "SEE ALSO".IX Header "SEE ALSO"\&\fI\fIpthread_attr_setstackaddr()\fI\fR,\&\fI\fIpthread_attr_setstacksize()\fI\fR,\&\fI\fIpthread_attr_setdetachstate()\fI\fR,\&\fI\fIpthread_create()\fI\fR,\&\fI<pthread.h\fR>..SH "_\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|_".IX Header "______________________________________________________________________".SH "NAME"\&\fBpthread_attr_setdetachstate,\fR \fBpthread_attr_getdetachstate\fR\&\- set and get detachstate attribute.SH "SYNOPSIS".IX Header "SYNOPSIS"#include <pthread.h>.PPint pthread_attr_setdetachstate(pthread_attr_t *\fIattr\fR, int \fIdetachstate\fR);int pthread_attr_getdetachstate(const pthread_attr_t *\fIattr\fR,int *\fIdetachstate\fR);.SH "DESCRIPTION".IX Header "DESCRIPTION"The\&\fIdetachstate\fRattribute controls whether the thread is created in a detached state.If the thread is created detached,then use of the \s-1ID\s0 of the newly created thread by the\&\fI\fIpthread_detach()\fI\fRor\&\fI\fIpthread_join()\fI\fRfunction is an error..PPThe\&\fI\fIpthread_attr_setdetachstate()\fI\fRand\&\fI\fIpthread_attr_getdetachstate()\fI\fR,respectively, set and get the\&\fIdetachstate\fRattribute in the\&\fIattr\fRobject..PPThe\&\fIdetachstate\fRcan be set to either \s-1PTHREAD_CREATE_DETACHED\s0 or \s-1PTHREAD_CREATE_JOINABLE\s0.A value of \s-1PTHREAD_CREATE_DETACHED\s0 causes all threads created with\&\fIattr\fRto be in the detached state, whereas using a value of\&\s-1PTHREAD_CREATE_JOINABLE\s0causes all threads created with\&\fIattr\fRto be in the joinable state.The default value of the\&\fIdetachstate\fRattribute is\&\s-1PTHREAD_CREATE_JOINABLE\s0 ..SH "RETURN VALUE".IX Header "RETURN VALUE"Upon successful completion,\&\fI\fIpthread_attr_setdetachstate()\fI\fRand\&\fI\fIpthread_attr_getdetachstate()\fI\fRreturn a value of 0.Otherwise, an error number is returned to indicate the error..PPThe\&\fI\fIpthread_attr_getdetachstate()\fI\fRfunction stores the value of the\&\fIdetachstate\fRattribute in\&\fIdetachstate\fRif successful..SH "ERRORS".IX Header "ERRORS"The\&\fI\fIpthread_attr_setdetachstate()\fI\fRfunction will fail if:.IP "[\s-1EINVAL\s0]" 4.IX Item "[EINVAL]"The value of\&\fIdetachstate\fRwas not valid.PPThese functions will not return an error code of [\s-1EINTR\s0]..SH "EXAMPLES".IX Header "EXAMPLES"None..SH "APPLICATION USAGE".IX Header "APPLICATION USAGE"None..SH "FUTURE DIRECTIONS".IX Header "FUTURE DIRECTIONS"None..SH "SEE ALSO".IX Header "SEE ALSO"\&\fI\fIpthread_attr_init()\fI\fR,\&\fI\fIpthread_attr_setstackaddr()\fI\fR,\&\fI\fIpthread_attr_setstacksize()\fI\fR,\&\fI\fIpthread_create()\fI\fR,\&\fI<pthread.h\fR>..SH "_\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|_".IX Header "______________________________________________________________________".SH "NAME"\&\fBpthread_attr_getguardsize,\fR \fBpthread_attr_setguardsize\fR \-get or set the thread guardsize attribute.SH "SYNOPSIS".IX Header "SYNOPSIS"#include <pthread.h>.PPint pthread_attr_getguardsize(const pthread_attr_t \fI*attr\fR,size_t \fI*guardsize\fR);int pthread_attr_setguardsize(pthread_attr_t \fI*attr\fR,size_t \fIguardsize\fR);.SH "DESCRIPTION".IX Header "DESCRIPTION"The \fIguardsize\fR attribute controls the sizeof the guard area for the created thread's stack. The \fIguardsize\fRattribute provides protection against overflow of thestack pointer. If a thread's stack is created with guardprotection, the implementation allocates extramemory at the overflow end of the stack as a buffer againststack overflow of the stack pointer. If an applicationoverflows into this buffer an error results (possiblyin a \s-1SIGSEGV\s0 signal being delivered to the thread)..PPThe \fIguardsize\fR attribute is provided to the applicationfor two reasons:.IP "1." 4Overflow protection can potentiallyresult in wasted system resources. An application that creates a largenumber of threads, and which knows its threads will never overflowtheir stack, can save system resources by turning off guard areas..IP "2." 4When threads allocate large data structures on the stack,large guard areas may be needed to detect stack overflow..PPThe\&\fI\fIpthread_attr_getguardsize()\fI\fRfunction gets the\&\fIguardsize\fR attribute in the \fIattr\fR object. This attribute isreturned in the \fIguardsize\fR parameter..PPThe\&\fI\fIpthread_attr_setguardsize()\fI\fRfunction sets the\&\fIguardsize\fR attribute in the \fIattr\fR object. The new value ofthis attribute is obtained from the \fIguardsize\fR parameter.If \fIguardsize\fR is zero, a guard area will not beprovided for threads created with \fIattr\fR. If \fIguardsize\fR isgreaterthan zero, a guard area of at least size \fIguardsize\fRbytes is provided for each thread created with \fIattr\fR..PPA conforming implementation is permitted to round upthe value contained in \fIguardsize\fR to a multipleof the configurable system variable \s-1PAGESIZE\s0 (see\&\fI<sys/mman.h\fR>).If an implementation rounds up thevalue of \fIguardsize\fR to a multiple of \s-1PAGESIZE\s0, a call to\&\fI\fIpthread_attr_getguardsize()\fI\fRspecifying \fIattr\fR willstore in the \fIguardsize\fR parameter the guard size specified by theprevious\&\fI\fIpthread_attr_setguardsize()\fI\fRfunction call..PPThe default value of the \fIguardsize\fR attribute is \s-1PAGESIZE\s0 bytes.The actual value of \s-1PAGESIZE\s0 isimplementation-dependent and may not be the same on all implementations..PPIf the \fIstackaddr\fR attribute has been set (that is, the calleris allocating and managing its own thread stacks), the\&\fIguardsize\fR attribute is ignored and no protectionwill be provided by the implementation. It is theresponsibility of the application to manage stack overflowalong with stack allocation and management in thiscase..SH "RETURN VALUE".IX Header "RETURN VALUE"If successful, the\&\fI\fIpthread_attr_getguardsize()\fI\fRand\&\fI\fIpthread_attr_setguardsize()\fI\fRfunctions return zero.Otherwise, an error number is returned to indicate the error..SH "ERRORS".IX Header "ERRORS"The\&\fI\fIpthread_attr_getguardsize()\fI\fRand\&\fI\fIpthread_attr_setguardsize()\fI\fRfunctions will fail if:.IP "[\s-1EINVAL\s0]" 4.IX Item "[EINVAL]"The attribute \fIattr\fR is invalid..IP "[\s-1EINVAL\s0]" 4.IX Item "[EINVAL]"The parameter \fIguardsize\fR is invalid..IP "[\s-1EINVAL\s0]" 4.IX Item "[EINVAL]"The parameter \fIguardsize\fR contains an invalid value..SH "EXAMPLES".IX Header "EXAMPLES"None..SH "APPLICATION USAGE".IX Header "APPLICATION USAGE"None..SH "FUTURE DIRECTIONS".IX Header "FUTURE DIRECTIONS"None..SH "SEE ALSO".IX Header "SEE ALSO"\&\fI<pthread.h\fR>..SH "_\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|_".IX Header "______________________________________________________________________".SH "NAME"\&\fBpthread_attr_setinheritsched,\fR \fBpthread_attr_getinheritsched\fR\&\- set and get inheritsched attribute(\fBREALTIME THREADS\fR).SH "SYNOPSIS".IX Header "SYNOPSIS"#include <pthread.h>.PPint pthread_attr_setinheritsched(pthread_attr_t *\fIattr\fR,int \fIinheritsched\fR);int pthread_attr_getinheritsched(const pthread_attr_t *\fIattr\fR,int *\fIinheritsched\fR);.SH "DESCRIPTION".IX Header "DESCRIPTION"The functions\&\fI\fIpthread_attr_setinheritsched()\fI\fRand\&\fI\fIpthread_attr_getinheritsched()\fI\fR,respectively, set and get the\&\fIinheritsched\fRattribute in the\&\fIattr\fRargument..PPWhen the attribute objects are used by\&\fI\fIpthread_create()\fI\fR,the\&\fIinheritsched\fRattribute determines how the other scheduling attributes ofthe created thread are to be set:.IP "\s-1PTHREAD_INHERIT_SCHED\s0" 4.IX Item "PTHREAD_INHERIT_SCHED"Specifies that the scheduling policy and associated attributesare to be inherited from the creating thread, and the schedulingattributes in this\&\fIattr\fRargument are to be ignored..IP "\s-1PTHREAD_EXPLICIT_SCHED\s0" 4.IX Item "PTHREAD_EXPLICIT_SCHED"Specifies that the scheduling policy and associated attributesare to be set to the corresponding values from this attribute object..PPThe symbols \s-1PTHREAD_INHERIT_SCHED\s0 and \s-1PTHREAD_EXPLICIT_SCHED\s0are defined in the header\&\fI<pthread.h\fR>..SH "RETURN VALUE".IX Header "RETURN VALUE"If successful, the\&\fI\fIpthread_attr_setinheritsched()\fI\fRand\&\fI\fIpthread_attr_getinheritsched()\fI\fRfunctions return zero.Otherwise, an error number is returned to indicate the error..SH "ERRORS".IX Header "ERRORS"The\&\fI\fIpthread_attr_setinheritsched()\fI\fRand\&\fI\fIpthread_attr_getinheritsched()\fI\fRfunctions will fail if:.IP "[\s-1ENOSYS\s0]" 4.IX Item "[ENOSYS]"The option _POSIX_THREAD_PRIORITY_SCHEDULING is not defined and theimplementation does not support the function..PPThe\&\fI\fIpthread_attr_setinheritsched()\fI\fRfunction may fail if:.IP "[\s-1EINVAL\s0]" 4.IX Item "[EINVAL]"The value of the attribute being set is not valid..IP "[\s-1ENOTSUP\s0]" 4.IX Item "[ENOTSUP]"An attempt was made to set the attribute to an unsupported value..SH "EXAMPLES".IX Header "EXAMPLES"None..SH "APPLICATION USAGE".IX Header "APPLICATION USAGE"After these attributes have been set, a thread can be created withthe specified attributes using\&\fI\fIpthread_create()\fI\fR.Using these routines does not affect the current running thread..SH "FUTURE DIRECTIONS".IX Header "FUTURE DIRECTIONS"None..SH "SEE ALSO".IX Header "SEE ALSO"\&\fI\fIpthread_attr_init()\fI\fR,\&\fI\fIpthread_attr_setscope()\fI\fR,\&\fI\fIpthread_attr_setschedpolicy()\fI\fR,\&\fI\fIpthread_attr_setschedparam()\fI\fR,\&\fI\fIpthread_create()\fI\fR,\&\fI<pthread.h\fR>,\&\fI\fIpthread_setschedparam()\fI\fR,\&\fI<sched.h\fR>..SH "_\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|__\|_".IX Header "______________________________________________________________________".SH "NAME"\&\fBpthread_attr_setschedparam,\fR \fBpthread_attr_getschedparam\fR\&\- set and get schedparam attribute.SH "SYNOPSIS".IX Header "SYNOPSIS"#include <pthread.h>.PPint pthread_attr_setschedparam(pthread_attr_t *\fIattr\fR,const struct sched_param *\fIparam\fR);int pthread_attr_getschedparam(const pthread_attr_t *\fIattr\fR,struct sched_param *\fIparam\fR);.SH "DESCRIPTION".IX Header "DESCRIPTION"The functions\&\fI\fIpthread_attr_setschedparam()\fI\fRand\&\fI\fIpthread_attr_getschedparam()\fI\fR,respectively, set and get the scheduling parameterattributes in the\&\fIattr\fRargument.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -