📄 pthread.pod
字号:
None.=head1 FUTURE DIRECTIONSNone.=head1 SEE ALSOI<pthread_cancel()>,I<pthread_setcancelstate()>,I<<pthread.h>>.=head1 ______________________________________________________________________=head1 NAMEB<pthread_cleanup_push,> B<pthread_cleanup_pop> - establish cancellation handlers=head1 SYNOPSIS#include <pthread.h>void pthread_cleanup_push(void (*I<routine>)(void*), void *I<arg>);void pthread_cleanup_pop(int I<execute>);=head1 DESCRIPTIONTheI<pthread_cleanup_push()>function pushes the specified cancellation cleanup handlerI<routine>onto the calling thread's cancellation cleanup stack.The cancellation cleanup handler is popped from thecancellation cleanup stack and invoked with the argumentI<arg>when: (a) the thread exits (that is, callsI<pthread_exit()>),(b) the thread acts upon a cancellation request, or(c) the thread callsI<pthread_cleanup_pop()>with a non-zeroI<execute>argument.TheI<pthread_cleanup_pop()>function removes the routine at the top of the calling thread'scancellation cleanup stack and optionally invokes it (ifI<execute>is non-zero).These functions may be implemented as macros and willappear as statements and in pairs within the same lexical scope (that is, theI<pthread_cleanup_push()>macro may be thought to expand to a token list whose firsttoken isB<`{'>withI<pthread_cleanup_pop()>expanding to a token list whose last token is the correspondingB<`}'>.The effect of callingI<longjmp()>orI<siglongjmp()>is undefined if there have been any calls toI<pthread_cleanup_push()>orI<pthread_cleanup_pop()>made without the matching callsince the jump buffer was filled.The effect of callingI<longjmp()>orI<siglongjmp()>from inside a cancellation cleanup handler is alsoundefined unless the jump buffer was also filled in thecancellation cleanup handler.=head1 RETURN VALUETheI<pthread_cleanup_push()>andI<pthread_cleanup_pop()>functions return no value.=head1 ERRORSNo errors are defined.These functions will not return an error code of [EINTR].=head1 EXAMPLESNone.=head1 APPLICATION USAGENone.=head1 FUTURE DIRECTIONSNone.=head1 SEE ALSOI<pthread_cancel()>,I<pthread_setcancelstate()>,I<<pthread.h>>.=head1 ______________________________________________________________________=head1 NAMEB<pthread_cond_signal,> B<pthread_cond_broadcast> - signal or broadcast acondition=head1 SYNOPSIS#include <pthread.h>int pthread_cond_signal(pthread_cond_t *I<cond>);int pthread_cond_broadcast(pthread_cond_t *I<cond>);=head1 DESCRIPTIONThese two functions are used to unblockthreads blocked on a condition variable.TheI<pthread_cond_signal()>call unblocks at least one of the threads that are blocked on thespecified condition variableI<cond>(if any threads are blocked onI<cond>).TheI<pthread_cond_broadcast()>call unblocks all threads currently blocked on the specified condition variableI<cond>.If more than one thread is blocked on a condition variable,the scheduling policy determines the order in which threads are unblocked.When each thread unblocked as a result of aI<pthread_cond_signal()>orI<pthread_cond_broadcast()>returns from its call toI<pthread_cond_wait()>orI<pthread_cond_timedwait()>,the thread owns the mutex with which it calledI<pthread_cond_wait()>orI<pthread_cond_timedwait()>.The thread(s) that are unblocked contend for the mutexaccording to the scheduling policy (if applicable),and as if each had calledI<pthread_mutex_lock()>.TheI<pthread_cond_signal()>orI<pthread_cond_broadcast()>functions may be called by a thread whether or not itcurrently owns the mutex that threads callingI<pthread_cond_wait()>orI<pthread_cond_timedwait()>have associated with the condition variable during their waits;however, if predictable scheduling behaviour is required,then that mutex is locked by the thread callingI<pthread_cond_signal()>orI<pthread_cond_broadcast()>.TheI<pthread_cond_signal()>andI<pthread_cond_broadcast()>functions have no effect if there are no threadscurrently blocked onI<cond>.=head1 RETURN VALUEIf successful, theI<pthread_cond_signal()>andI<pthread_cond_broadcast()>functions return zero.Otherwise, an error number is returned to indicate the error.=head1 ERRORSTheI<pthread_cond_signal()>andI<pthread_cond_broadcast()>function may fail if:=over 4=item [EINVAL]The valueI<cond>does not refer to an initialised condition variable.=backThese functions will not return an error code of [EINTR].=head1 EXAMPLESNone.=head1 APPLICATION USAGENone.=head1 FUTURE DIRECTIONSNone.=head1 SEE ALSOI<pthread_cond_init()>,I<pthread_cond_wait()>,I<pthread_cond_timedwait()>,I<<pthread.h>>.=head1 ______________________________________________________________________=head1 NAMEB<pthread_cond_init,> B<pthread_cond_destroy> - initialise and destroycondition variables=head1 SYNOPSIS#include <pthread.h>int pthread_cond_init(pthread_cond_t *I<cond>,const pthread_condattr_t *I<attr>);int pthread_cond_destroy(pthread_cond_t *I<cond>);pthread_cond_t I<cond> = PTHREAD_COND_INITIALIZER;=head1 DESCRIPTIONThe functionI<pthread_cond_init()>initialises the condition variable referenced byI<cond>with attributes referenced byI<attr>.IfI<attr>is NULL,the default condition variable attributes are used;the effect is the same as passing the addressof a default condition variable attributes object.Upon successful initialisation,the state of the condition variable becomes initialised.Attempting to initialise an already initialisedcondition variableresults in undefined behaviour.The functionI<pthread_cond_destroy()>destroys the given condition variable specified byI<cond>;the object becomes, in effect, uninitialised.An implementation may causeI<pthread_cond_destroy()>to set the object referenced byI<cond>to an invalid value.A destroyed condition variable objectcan be re-initialised usingI<pthread_cond_init()>;the results of otherwise referencing the object after it has been destroyedare undefined.It is safe to destroy an initialised condition variableupon which no threads are currently blocked.Attempting to destroy a condition variableupon which other threads are currently blockedresults in undefined behaviour.In cases where default condition variable attributes are appropriate,the macro PTHREAD_COND_INITIALIZERcan be used to initialise condition variables that are statically allocated.The effect is equivalent to dynamic initialisation by a call toI<pthread_cond_init()>with parameterI<attr>specified as NULL, except that no error checks are performed.=head1 RETURN VALUEIf successful, theI<pthread_cond_init()>andI<pthread_cond_destroy()>functions return zero.Otherwise, an error number is returned to indicate the error.The [EBUSY] and [EINVAL]error checks, if implemented,act as if they were performed immediatelyat the beginning of processing for the functionand caused an error returnprior to modifying the state of the condition variable specified byI<cond>.=head1 ERRORSTheI<pthread_cond_init()>function will fail if:=over 4=item [EAGAIN]The system lacked the necessary resources (otherthan memory) to initialise another condition variable.=item [ENOMEM]Insufficient memory exists to initialise the condition variable.=backTheI<pthread_cond_init()>function may fail if:=over 4=item [EBUSY]The implementation has detected an attemptto re-initialise the object referenced byI<cond>,a previously initialised, butnot yet destroyed, condition variable.=item [EINVAL]The value specified byI<attr>is invalid.=backTheI<pthread_cond_destroy()>function may fail if:=over 4=item [EBUSY]The implementation has detected an attempt to destroythe object referenced byI<cond>while it is referenced(for example, while being used in aI<pthread_cond_wait()>orI<pthread_cond_timedwait()>)by another thread.=item [EINVAL]The value specified byI<cond>is invalid.=backThese functions will not return an error code of [EINTR].=head1 EXAMPLESNone.=head1 APPLICATION USAGENone.=head1 FUTURE DIRECTIONSNone.=head1 SEE ALSOI<pthread_cond_signal()>,I<pthread_cond_broadcast()>,I<pthread_cond_wait()>,I<pthread_cond_timedwait()>,I<<pthread.h>>.=head1 ______________________________________________________________________=head1 NAMEB<pthread_cond_init,> B<pthread_cond_destroy> - initialise and destroycondition variables=head1 SYNOPSIS#include <pthread.h>int pthread_cond_init(pthread_cond_t *I<cond>,const pthread_condattr_t *I<attr>);int pthread_cond_destroy(pthread_cond_t *I<cond>);pthread_cond_t I<cond> = PTHREAD_COND_INITIALIZER;=head1 DESCRIPTIONThe functionI<pthread_cond_init()>initialises the condition variable referenced byI<cond>with attributes referenced byI<attr>.IfI<attr>is NULL,the default condition variable attributes are used;the effect is the same as passing the addressof a default condition variable attributes object.Upon successful initialisation,the state of the condition variable becomes initialised.Attempting to initialise an already initialisedcondition variableresults in undefined behaviour.The functionI<pthread_cond_destroy()>destroys the given condition variable specified byI<cond>;the object becomes, in effect, uninitialised.An implementation may causeI<pthread_cond_destroy()>to set the object referenced byI<cond>to an invalid value.A destroyed condition variable objectcan be re-initialised usingI<pthread_cond_init()>;the results of otherwise referencing the object after it has been destroyedare undefined.It is safe to destroy an initialised condition variableupon which no threads are currently blocked.Attempting to destroy a condition variableupon which other threads are currently blockedresults in undefined behaviour.In cases where default condition variable attributes are appropriate,the macro PTHREAD_COND_INITIALIZERcan be used to initialise condition variables that are statically allocated.The effect is equivalent to dynamic initialisation by a call toI<pthread_cond_init()>with parameterI<attr>specified as NULL, except that no error checks are performed.=head1 RETURN VALUEIf successful, theI<pthread_cond_init()>andI<pthread_cond_destroy()>functions return zero.Otherwise, an error number is returned to indicate the error.The [EBUSY] and [EINVAL]error checks, if implemented,act as if they were performed immediatelyat the beginning of processing for the functionand caused an error returnprior to modifying the state of the condition variable specified byI<cond>.=head1 ERRORSTheI<pthread_cond_init()>function will fail if:=over 4=item [EAGAIN]The system lacked the necessary resources (otherthan memory) to initialise another condition variable.=item [ENOMEM]Insufficient memory exists to initialise the condition variable.=backTheI<pthread_cond_init()>function may fail if:=over 4=item [EBUSY]The implementation has detected an attemptto re-initialise the object referenced byI<cond>,a previously initialised, butnot yet destroyed, condition variable.=item [EINVAL]The value specified byI<attr>is invalid.=backTheI<pthread_cond_destroy()>function may fail if:=over 4=item [EBUSY]The implementation has detected an attempt to destroythe object referenced byI<cond>while it is referenced(for example, while being used in aI<pthread_cond_wait()>orI<pthread_cond_timedwait()>)by another thread.=item [EINVAL]The value specified byI<cond>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -