pthread_setcanceltype(3) — Linux manual page



NAME         top

       pthread_setcancelstate,  pthread_setcanceltype  -  set  cancelability
       state and type

SYNOPSIS         top

       #include <pthread.h>

       int pthread_setcancelstate(int state, int *oldstate);
       int pthread_setcanceltype(int type, int *oldtype);

       Compile and link with -pthread.

DESCRIPTION         top

       The pthread_setcancelstate() sets the cancelability state of the
       calling thread to the value given in state.  The previous
       cancelability state of the thread is returned in the buffer pointed

              The thread is cancelable.  This is the default cancelability
              state in all new threads, including the initial thread.  The
              thread's cancelability type determines when a cancelable
              thread will respond to a cancellation request.

              The thread is not cancelable.  If a cancellation request is
              received, it is blocked until cancelability is enabled.

       The pthread_setcanceltype() sets the cancelability type of the
       calling thread to the value given in type.  The previous
       cancelability type of the thread is returned in the buffer pointed to

              A cancellation request is deferred until the thread next calls
              This is the default cancelability type in all new threads,
              including the initial thread.

              Even with deferred cancellation, a cancellation point in an
              asynchronous signal handler may still be acted upon and the
              effect is as if it was an asynchronous cancellation.

              be canceled immediately upon receiving a cancellation request,
              but the system doesn't guarantee this.)

       atomic with respect to other threads in the process calling the same

RETURN VALUE         top

       error number.

ERRORS         top

       The pthread_setcancelstate() can fail with the following error:

       EINVAL Invalid value for state.

       The pthread_setcanceltype() can fail with the following error:

       EINVAL Invalid value for type.

ATTRIBUTES         top

       For an explanation of the terms used in this section, see

       │Interface                 Attribute           Value   │
       │pthread_setcancelstate(), │ Thread safety       │ MT-Safe │
       │pthread_setcanceltype()   │                     │         │
       │pthread_setcancelstate(), │ Async-cancel-safety │ AC-Safe │
       │pthread_setcanceltype()   │                     │         │

CONFORMING TO         top

       POSIX.1-2001, POSIX.1-2008.

NOTES         top

       For details of what happens when a thread is canceled, see

       Briefly disabling cancelability is useful if a thread performs some
       critical action that must not be interrupted by a cancellation
       request.  Beware of disabling cancelability for long periods, or
       around operations that may block for long periods, since that will
       render the thread unresponsive to cancellation requests.

   Asynchronous cancelability
       Setting the cancelability type to PTHREAD_CANCEL_ASYNCHRONOUS is
       cannot safely reserve resources (e.g., allocating memory with
       Reserving resources is unsafe because the application has no way of
       knowing what the state of these resources is when the thread is
       canceled; that is, did cancellation occur before the resources were
       in an inconsistent state if cancellation occurs in the middle of the

       Functions that can be safely asynchronously canceled are called
       only that pthread_cancel(3), pthread_setcancelstate(), and
       library functions can't be safely called from an asynchronously
       cancelable thread.

       One of the few circumstances in which asynchronous cancelability is
       bound loop.

   Portability notes
       The Linux threading implementations permit the oldstate argument of
       pthread_setcancelstate() to be NULL, in which case the information
       about the previous cancelability state is not returned to the caller.
       Many other implementations also permit a NULL oldstat argument, but
       set of statements applies for the oldtype argument of

EXAMPLES         top

       See pthread_cancel(3).

SEE ALSO         top


COLOPHON         top

       description of the project, information about reporting bugs, and the
       latest version of this page, can be found at

Linux                            2020-06-09        PTHREAD_SETCANCELSTATE(3)

Pages that refer to this page: pthread_cancel(3)pthread_cleanup_pop_restore_np(3)pthread_cleanup_push_defer_np(3)pthread_kill_other_threads_np(3)pthreads(7)