Professional Multicore Programming: Design and Implementation for C++ Developers
by Cameron Hughes, Tracey Hughes
Name
NAME
pthread_cancel — cancel execution of a thread
SYNOPSIS
THR #include <pthread.h>
int pthread_cancel(pthread_t thread);DESCRIPTION
The pthread_cancel() function shall request that thread be canceled. The target thread's cancelability state and type determines when the cancelation takes effect. When the cancelation is acted on, the cancelation cleanup handlers for thread shall be called. When the last cancelation cleanup handler returns, the thread-specific data destructor functions shall be called for thread. When the last destructor function returns, thread shall be terminated.
The cancelation processing in the target thread shall run asynchronously with respect to the calling thread returning from pthread_cancel().
RETURN VALUE
If successful, the pthread_cancel() function shall return zero; otherwise, an error number shall be returned to indicate the error.
ERRORS
The pthread_cancel() function may fail if:
[ESRCH] | No thread could be found corresponding to that specified by the given thread ID. |
The pthread_cancel() function shall not return an error code of [EINTR].
EXAMPLES
None.
APPLICATION USAGE
None.
RATIONALE
Two alternative functions were considered for sending the cancelation notification to a thread. One would be to define a new SIGCANCEL signal that had the cancelation semantics when delivered; the other was to define the new pthread_cancel() function, which would trigger the cancelation semantics.
The advantage of a new signal was that so much of the delivery criteria were identical ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access