Xenomai API
2.5.6.1
|
Thread cancellation. More...
Functions | |
int | pthread_cancel (pthread_t thread) |
Cancel a thread. | |
void | pthread_cleanup_push (cleanup_routine_t *routine, void *arg) |
Register a cleanup handler to be executed at the time of cancellation. | |
void | pthread_cleanup_pop (int execute) |
Unregister the last registered cleanup handler. | |
int | pthread_setcanceltype (int type, int *oldtype_ptr) |
Set cancelability type of the current thread. | |
int | pthread_setcancelstate (int state, int *oldstate_ptr) |
Set cancelability state of the current thread. | |
void | pthread_testcancel (void) |
Test if a cancellation request is pending. |
Thread cancellation.
Cancellation is the mechanism by which a thread can terminate the execution of a Xenomai POSIX skin thread (created with pthread_create()). More precisely, a thread can send a cancellation request to a Xenomai POSIX skin thread and depending on its cancelability type (see pthread_setcanceltype()) and state (see pthread_setcancelstate()), the target thread can then either ignore the request, honor it immediately, or defer it till it reaches a cancellation point. When threads are first created by pthread_create(), they always defer cancellation requests.
When a thread eventually honors a cancellation request, it behaves as if pthread_exit(PTHREAD_CANCELED) was called. All cleanup handlers are executed in reverse order, finalization functions for thread-specific data are called, and finally the thread stops executing. If the canceled thread was joinable, the return value PTHREAD_CANCELED is provided to whichever thread calls pthread_join() on it. See pthread_exit() for more information.
Cancellation points are the points where the thread checks for pending cancellation requests and performs them. The POSIX threads functions pthread_join(), pthread_cond_wait(), pthread_cond_timedwait(), pthread_testcancel(), sem_wait(), sem_timedwait(), sigwait(), sigwaitinfo() and sigtimedwait() are cancellation points.
int pthread_cancel | ( | pthread_t | thread | ) |
Cancel a thread.
This service sends a cancellation request to the thread thread and returns immediately. Depending on the target thread cancelability state (see pthread_setcancelstate()) and type (see pthread_setcanceltype()), its termination is either immediate, deferred or ignored.
When the cancellation request is handled and before the thread is terminated, the cancellation cleanup handlers (registered with the pthread_cleanup_push() service) are called, then the thread-specific data destructor functions (registered with pthread_key_create()).
References xnpod_schedule(), and xnpod_unblock_thread().
Referenced by rt_task_delete().
void pthread_cleanup_pop | ( | int | execute | ) |
Unregister the last registered cleanup handler.
If the calling thread is a Xenomai POSIX skin thread (i.e. created with pthread_create()), this service unregisters the last routine which was registered with pthread_cleanup_push() and call it if execute is not null.
If the caller context is invalid (not a Xenomai POSIX skin thread), this service has no effect.
This service may be called at any place, but for maximal portability, should only called in the same lexical scope as the matching call to pthread_cleanup_push().
execute | if non zero, the last registered cleanup handler should be executed before it is unregistered. |
Referenced by rt_cond_wait(), and rt_cond_wait_until().
void pthread_cleanup_push | ( | cleanup_routine_t * | routine, |
void * | arg | ||
) |
Register a cleanup handler to be executed at the time of cancellation.
This service registers the given routine to be executed a the time of cancellation of the calling thread, if this thread is a Xenomai POSIX skin thread (i.e. created with the pthread_create() service). If the caller context is invalid (not a Xenomai POSIX skin thread), this service has no effect.
If allocation from the system heap fails (because the system heap size is to small), this service fails silently.
The routines registered with this service get called in LIFO order when the calling thread calls pthread_exit() or is canceled, or when it calls the pthread_cleanup_pop() service with a non null argument.
routine | the cleanup routine to be registered; |
arg | the argument associated with this routine. |
Referenced by rt_cond_wait(), and rt_cond_wait_until().
int pthread_setcancelstate | ( | int | state, |
int * | oldstate_ptr | ||
) |
Set cancelability state of the current thread.
This service atomically set the cancelability state of the calling thread and returns its previous value at the address oldstate_ptr, if the calling thread is a Xenomai POSIX skin thread (i.e. created with the pthread_create service).
The cancelability state of a POSIX thread may be:
state | new cancelability state of the calling thread; |
oldstate_ptr | address where the old cancelability state will be stored on success. |
int pthread_setcanceltype | ( | int | type, |
int * | oldtype_ptr | ||
) |
Set cancelability type of the current thread.
This service atomically sets the cancelability type of the calling thread, and return its previous value at the address oldtype_ptr, if this thread is a Xenomai POSIX skin thread (i.e. was created with the pthread_create() service).
The cancelability type of a POSIX thread may be:
type | new cancelability type of the calling thread; |
oldtype_ptr | address where the old cancelability type will be stored on success. |
Referenced by rt_cond_wait(), rt_cond_wait_until(), rt_intr_wait(), rt_queue_read(), rt_queue_read_until(), rt_queue_receive(), rt_queue_receive_until(), rt_queue_send(), rt_queue_write(), rt_sem_p(), rt_sem_p_until(), rt_task_send(), rt_task_shadow(), rt_task_sleep(), rt_task_sleep_until(), and rt_task_wait_period().
void pthread_testcancel | ( | void | ) |
Test if a cancellation request is pending.
This function creates a cancellation point if the calling thread is a Xenomai POSIX skin thread (i.e. created with the pthread_create() service).
This function is a cancellation point. It has no effect if cancellation is disabled.
Referenced by rt_cond_wait(), and rt_cond_wait_until().