📄 pthread.pod
字号:
=item [EINVAL]The value ofI<stacksize>is less than PTHREAD_STACK_MIN or exceeds a system-imposed limit.=backThese functions will not return an error code of [EINTR].=head1 EXAMPLESNone.=head1 APPLICATION USAGENone.=head1 FUTURE DIRECTIONSNone.=head1 SEE ALSOI<pthread_attr_init()>,I<pthread_attr_setstackaddr()>,I<pthread_attr_setdetachstate()>,I<pthread_create()>,I<<limits.h>>,I<<pthread.h>>.=head1 ______________________________________________________________________=head1 NAMEB<pthread_attr_init,> B<pthread_attr_destroy>- initialise and destroy threads attribute object=head1 SYNOPSIS#include <pthread.h>int pthread_attr_init(pthread_attr_t *I<attr>);int pthread_attr_destroy(pthread_attr_t *I<attr>);=head1 DESCRIPTIONThe functionI<pthread_attr_init()>initialises a thread attributes objectI<attr>with the default value for all of the individual attributesused by a given implementation.The resulting attribute object(possibly modified by setting individual attribute values),when used byI<pthread_create()>,defines the attributes of the thread created.A single attributes object can be used in multiple simultaneous calls toI<pthread_create()>.TheI<pthread_attr_destroy()>function is used to destroy a thread attributes object.An implementation may causeI<pthread_attr_destroy()>to setI<attr>to an implementation-dependent invalid value.The behaviour of using the attribute after it has been destroyed is undefined.=head1 RETURN VALUEUpon successful completion,I<pthread_attr_init()>andI<pthread_attr_destroy()>return a value of 0.Otherwise, an error number is returned to indicate the error.=head1 ERRORSTheI<pthread_attr_init()>function will fail if:=over 4=item [ENOMEM]Insufficient memory exists to initialise the thread attributes object.=backThese functions will not return an error code of [EINTR].=head1 EXAMPLESNone.=head1 APPLICATION USAGENone.=head1 FUTURE DIRECTIONSNone.=head1 SEE ALSOI<pthread_attr_setstackaddr()>,I<pthread_attr_setstacksize()>,I<pthread_attr_setdetachstate()>,I<pthread_create()>,I<<pthread.h>>.=head1 ______________________________________________________________________=head1 NAMEB<pthread_attr_setdetachstate,> B<pthread_attr_getdetachstate>- set and get detachstate attribute=head1 SYNOPSIS#include <pthread.h>int pthread_attr_setdetachstate(pthread_attr_t *I<attr>, int I<detachstate>);int pthread_attr_getdetachstate(const pthread_attr_t *I<attr>,int *I<detachstate>);=head1 DESCRIPTIONTheI<detachstate>attribute controls whether the thread is created in a detached state.If the thread is created detached,then use of the ID of the newly created thread by theI<pthread_detach()>orI<pthread_join()>function is an error.TheI<pthread_attr_setdetachstate()>andI<pthread_attr_getdetachstate()>,respectively, set and get theI<detachstate>attribute in theI<attr>object.TheI<detachstate>can be set to either PTHREAD_CREATE_DETACHED or PTHREAD_CREATE_JOINABLE.A value of PTHREAD_CREATE_DETACHED causes all threads created withI<attr>to be in the detached state, whereas using a value ofPTHREAD_CREATE_JOINABLEcauses all threads created withI<attr>to be in the joinable state.The default value of theI<detachstate>attribute isPTHREAD_CREATE_JOINABLE .=head1 RETURN VALUEUpon successful completion,I<pthread_attr_setdetachstate()>andI<pthread_attr_getdetachstate()>return a value of 0.Otherwise, an error number is returned to indicate the error.TheI<pthread_attr_getdetachstate()>function stores the value of theI<detachstate>attribute inI<detachstate>if successful.=head1 ERRORSTheI<pthread_attr_setdetachstate()>function will fail if:=over 4=item [EINVAL]The value ofI<detachstate>was not valid=backThese functions will not return an error code of [EINTR].=head1 EXAMPLESNone.=head1 APPLICATION USAGENone.=head1 FUTURE DIRECTIONSNone.=head1 SEE ALSOI<pthread_attr_init()>,I<pthread_attr_setstackaddr()>,I<pthread_attr_setstacksize()>,I<pthread_create()>,I<<pthread.h>>.=head1 ______________________________________________________________________=head1 NAMEB<pthread_attr_getguardsize,> B<pthread_attr_setguardsize> -get or set the thread guardsize attribute=head1 SYNOPSIS#include <pthread.h>int pthread_attr_getguardsize(const pthread_attr_t I<*attr>,size_t I<*guardsize>);int pthread_attr_setguardsize(pthread_attr_t I<*attr>,size_t I<guardsize>);=head1 DESCRIPTIONThe I<guardsize> attribute controls the sizeof the guard area for the created thread's stack. The I<guardsize>attribute 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 SIGSEGV signal being delivered to the thread).The I<guardsize> attribute is provided to the applicationfor two reasons:=over 4=item 1.Overflow 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.=item 2.When threads allocate large data structures on the stack,large guard areas may be needed to detect stack overflow.=backTheI<pthread_attr_getguardsize()>function gets theI<guardsize> attribute in the I<attr> object. This attribute isreturned in the I<guardsize> parameter.TheI<pthread_attr_setguardsize()>function sets theI<guardsize> attribute in the I<attr> object. The new value ofthis attribute is obtained from the I<guardsize> parameter.If I<guardsize> is zero, a guard area will not beprovided for threads created with I<attr>. If I<guardsize> isgreaterthan zero, a guard area of at least size I<guardsize>bytes is provided for each thread created with I<attr>.A conforming implementation is permitted to round upthe value contained in I<guardsize> to a multipleof the configurable system variable PAGESIZE (seeI<<sys/mman.h>>).If an implementation rounds up thevalue of I<guardsize> to a multiple of PAGESIZE, a call toI<pthread_attr_getguardsize()>specifying I<attr> willstore in the I<guardsize> parameter the guard size specified by thepreviousI<pthread_attr_setguardsize()>function call.The default value of the I<guardsize> attribute is PAGESIZE bytes.The actual value of PAGESIZE isimplementation-dependent and may not be the same on all implementations.If the I<stackaddr> attribute has been set (that is, the calleris allocating and managing its own thread stacks), theI<guardsize> 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.=head1 RETURN VALUEIf successful, theI<pthread_attr_getguardsize()>andI<pthread_attr_setguardsize()>functions return zero.Otherwise, an error number is returned to indicate the error.=head1 ERRORSTheI<pthread_attr_getguardsize()>andI<pthread_attr_setguardsize()>functions will fail if:=over 4=item [EINVAL]The attribute I<attr> is invalid.=item [EINVAL]The parameter I<guardsize> is invalid.=item [EINVAL]The parameter I<guardsize> contains an invalid value.=back=head1 EXAMPLESNone.=head1 APPLICATION USAGENone.=head1 FUTURE DIRECTIONSNone.=head1 SEE ALSOI<<pthread.h>>.=head1 ______________________________________________________________________=head1 NAMEB<pthread_attr_setinheritsched,> B<pthread_attr_getinheritsched>- set and get inheritsched attribute(B<REALTIME THREADS>)=head1 SYNOPSIS#include <pthread.h>int pthread_attr_setinheritsched(pthread_attr_t *I<attr>,int I<inheritsched>);int pthread_attr_getinheritsched(const pthread_attr_t *I<attr>,int *I<inheritsched>);=head1 DESCRIPTIONThe functionsI<pthread_attr_setinheritsched()>andI<pthread_attr_getinheritsched()>,respectively, set and get theI<inheritsched>attribute in theI<attr>argument.When the attribute objects are used byI<pthread_create()>,theI<inheritsched>attribute determines how the other scheduling attributes ofthe created thread are to be set:=over 4=item PTHREAD_INHERIT_SCHEDSpecifies that the scheduling policy and associated attributesare to be inherited from the creating thread, and the schedulingattributes in thisI<attr>argument are to be ignored.=item PTHREAD_EXPLICIT_SCHEDSpecifies that the scheduling policy and associated attributesare to be set to the corresponding values from this attribute object.=backThe symbols PTHREAD_INHERIT_SCHED and PTHREAD_EXPLICIT_SCHEDare defined in the headerI<<pthread.h>>.=head1 RETURN VALUEIf successful, theI<pthread_attr_setinheritsched()>andI<pthread_attr_getinheritsched()>functions return zero.Otherwise, an error number is returned to indicate the error.=head1 ERRORSTheI<pthread_attr_setinheritsched()>andI<pthread_attr_getinheritsched()>functions will fail if:=over 4=item [ENOSYS]The option _POSIX_THREAD_PRIORITY_SCHEDULING is not defined and theimplementation does not support the function.=backTheI<pthread_attr_setinheritsched()>function may fail if:=over 4=item [EINVAL]The value of the attribute being set is not valid.=item [ENOTSUP]An attempt was made to set the attribute to an unsupported value.=back=head1 EXAMPLESNone.=head1 APPLICATION USAGEAfter these attributes have been set, a thread can be created withthe specified attributes usingI<pthread_create()>.Using these routines does not affect the current running thread.=head1 FUTURE DIRECTIONSNone.=head1 SEE ALSOI<pthread_attr_init()>,I<pthread_attr_setscope()>,I<pthread_attr_setschedpolicy()>,I<pthread_attr_setschedparam()>,I<pthread_create()>,I<<pthread.h>>,I<pthread_setschedparam()>,I<<sched.h>>.=head1 ______________________________________________________________________=head1 NAMEB<pthread_attr_setschedparam,> B<pthread_attr_getschedparam>- set and get schedparam attribute=head1 SYNOPSIS#include <pthread.h>int pthread_attr_setschedparam(pthread_attr_t *I<attr>,const struct sched_param *I<param>);int pthread_attr_getschedparam(const pthread_attr_t *I<attr>,struct sched_param *I<param>);=head1 DESCRIPTIONThe functionsI<pthread_attr_setschedparam()>andI<pthread_attr_getschedparam()>,respectively, set and get the scheduling parameterattributes in theI<attr>argument.The contents of theI<param>structure are defined inI<<sched.h>>.For the SCHED_FIFO and SCHED_RR policies,the only required member ofI<param>isI<sched_priority>.=head1 RETURN VALUEIf successful, theI<pthread_attr_setschedparam()>andI<pthread_attr_getschedparam()>functions return zero.Otherwise, an error number is returned to indicate the error.=head1 ERRORSTheI<pthread_attr_setschedparam()>function may fail if:=over 4=item [EINVAL]The value of the attribute being set is not valid.=item [ENOTSUP]An attempt was made to set the attribute to an unsupported value.=backTheI<pthread_attr_setschedparam()>andI<pthread_attr_getschedparam()>functions will not return an error code of [EINTR].=head1 EXAMPLESNone.=head1 APPLICATION USAGEAfter these attributes have been set, a thread can be created withthe specified attributes using
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -