Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/t/threadcancel.html on line 1

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/t/threadcancel.html on line 1

Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/t/threadcancel.html on line 8

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/t/threadcancel.html on line 8

ThreadCancel(), ThreadCancel_r()

Cancel a thread

Synopsis:

#include <sys/neutrino.h>

int ThreadCancel( int tid,
                  void (*canstub)(void) );

int ThreadCancel_r( int tid,
                    void (*canstub)(void) );

Arguments:

tid
The ID of the thread that you want to destroy, as returned by ThreadCreate().
canstub
A pointer to the location that you want the thread to jump to when the cancellation occurs; see below.

Note: You must provide a canstub function.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

These kernel calls request that the thread specified by tid be canceled. The target thread's cancelability state and type determine when the cancellation takes effect.

The ThreadCancel() and ThreadCancel_r() functions are identical, except in the way they indicate errors. See the Returns section for details.


Note: Instead of using these kernel calls directly, consider calling pthread_cancel().

When the cancellation is acted upon, the thread jumps to the location specified by canstub. This stub should call cancellation cleanup handlers for the thread. When the last cancellation cleanup handler returns, the stub must terminate the thread using:

ThreadDestroy( 0, -1, PTHREAD_CANCEL);

Unlike ThreadDestroy(), which destroys a thread immediately, ThreadCancel() requests that the target thread execute any cleanup code and then terminate at its earliest convenience.

The cancellation processing in the target thread runs asynchronously with respect to the calling thread, which doesn't block.

The combinations of cancelability state and type are as follows:

State Type Description
Disabled Deferred Cancel requests are made pending
Disabled Async Cancel requests are made pending
Enabled Deferred Cancellation happens at the next cancellation point. These are at explicitly coded calls to pthread_testcancel() or an attempt to enter a blocking state in any of the calls defined in the table below. All kernel calls that block are cancellation points, with the exception of MsgSendvnc() and SyncMutexLock().
Enabled Async Cancellation happens immediately.

Use pthread_setcancelstate(), and pthread_setcanceltype() to set the state and type.

POSIX defines a list of functions that are cancellation points; some functions that aren't listed there may also be cancellation points. For a full list, see Cancellation points in the appendix, Summary of Safety Information. Any function that calls a blocking kernel call that's a cancellation point will itself become a cancellation point when the kernel call is made. The most common blocking kernel call in library code is MsgSendv().

Blocking states

These calls don't block.

Returns:

The only difference between these functions is the way they indicate errors:

ThreadCancel()
If an error occurs, the function returns -1 and sets errno. Any other value returned indicates success.
ThreadCancel_r()
EOK is returned on success. This function does NOT set errno. If an error occurs, any value in the Errors section may be returned.

Errors:

ESRCH
The thread indicated by tid doesn't exist.

Classification:

QNX Neutrino

Safety:
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes

See also:

pthread_cancel(), pthread_setcancelstate(), pthread_setcanceltype(), pthread_testcancel(), ThreadCreate(), ThreadDestroy()


Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/t/threadcancel.html on line 279

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/t/threadcancel.html on line 279