Provided by: manpages-ru-dev_4.27.0-1_all bug

НАИМЕНОВАНИЕ

       pthread_setcancelstate, pthread_setcanceltype - изменяет состояния и тип отменяемости

БИБЛИОТЕКА

       Библиотека потоков POSIX (libpthread, -lpthread)

ОБЗОР

       #include <pthread.h>

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

ОПИСАНИЕ

       Функция  pthread_setcancelstate()  изменяет  состояние  отменяемости  вызывающий  нити на значение state.
       Предыдущее состояние отменяемости нити возвращается в буфер, на который  указывает  oldstate.  Аргументом
       state должно быть одно из следующих значений:

       PTHREAD_CANCEL_ENABLE
              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 cancelation request.

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

       Функция pthread_setcanceltype() изменяет тип отменяемости вызывающий нити на  значение  type.  Предыдущий
       тип  отменяемости  нити  возвращается в буфер, на который указывает oldstate. Аргументом type должно быть
       одно из следующих значений:

       PTHREAD_CANCEL_DEFERRED
              A cancelation request is deferred until the thread next calls a function  that  is  a  cancelation
              point (see pthreads(7)).  This is the default cancelability type in all new threads, including the
              initial thread.

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

       PTHREAD_CANCEL_ASYNCHRONOUS
              The  thread  can  be  canceled  at  any  time.   (Typically,  it will be canceled immediately upon
              receiving a cancelation request, but the system doesn't guarantee this.)

       Операции установки и получения (set-and-get), выполняемые каждой из этих функций, являются атомарными для
       предотвращения пересечения с другими процессами, вызывающими ту же функцию.

ВОЗВРАЩАЕМОЕ ЗНАЧЕНИЕ

       При успешном выполнении эти функции возвращают 0; при ошибке возвращается ненулевой номер ошибки.

ОШИБКИ

       Функция pthread_setcancelstate() может завершиться со следующей ошибкой:

       EINVAL Неправильное значение для state.

       Функция pthread_setcanceltype() может завершиться со следующей ошибкой:

       EINVAL Неправильное значение для type.

АТРИБУТЫ

       Описание терминов данного раздела смотрите в attributes(7).
       ┌──────────────────────────────────────────────────────────┬─────────────────────────────────┬──────────┐
       │ ИнтерфейсАтрибутЗначение │
       ├──────────────────────────────────────────────────────────┼─────────────────────────────────┼──────────┤
       │ pthread_setcancelstate(), pthread_setcanceltype()        │ Безвредность в нитях            │ MT-Safe  │
       ├──────────────────────────────────────────────────────────┼─────────────────────────────────┼──────────┤
       │ pthread_setcancelstate(), pthread_setcanceltype()        │ Безопасность асинхронной отмены │ AC-Safe  │
       └──────────────────────────────────────────────────────────┴─────────────────────────────────┴──────────┘

СТАНДАРТЫ

       POSIX.1-2008.

ИСТОРИЯ

       glibc 2.0 POSIX.1-2001.

ПРИМЕЧАНИЯ

       For details of what happens when a thread is canceled, see pthread_cancel(3).

       Briefly disabling cancelability is useful if a thread performs some critical  action  that  must  not  be
       interrupted  by  a  cancelation  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 cancelation
       requests.

   Асинхронная отменяемость
       Setting the cancelability type to PTHREAD_CANCEL_ASYNCHRONOUS is rarely useful.  Since the  thread  could
       be  canceled  at  any  time, it cannot safely reserve resources (e.g., allocating memory with malloc(3)),
       acquire mutexes, semaphores, or locks, and so on.  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
       cancelation occur before the resources were reserved, while  they  were  reserved,  or  after  they  were
       released? Furthermore, some internal data structures (e.g., the linked list of free blocks managed by the
       malloc(3)   family of functions) may be left in an inconsistent state if cancelation occurs in the middle
       of the function call.  Consequently, clean-up handlers cease to be useful.

       Функции,  которые  можно  безопасно  асинхронно  отменять  называются  функциями   async-cancel-safe.   В
       POSIX.1-2001   и   POSIX.1-2008   требуется,   чтобы   такими   функция  были  только  pthread_cancel(3),
       pthread_setcancelstate() и pthread_setcanceltype(). В общем, другие функции библиотеки  нельзя  безопасно
       вызывать из асинхронно отменяемой нити.

       One of the few circumstances in which asynchronous cancelability is useful is for cancelation of a thread
       that is in a pure compute-bound loop.

   Замечания о переносимости
       Реализации  нитей  в  Linux  позволяют  присваивать  аргументу  oldstate функции pthread_setcancelstate()
       значение NULL; в этом случае информация о предыдущем состоянии отмены не возвращается вызывающему. Многие
       другие реализации  также  допускают  NULL  в  качестве  значения  oldstat,  но  POSIX.1  этот  случай  не
       рассматривается,  поэтому переносимые приложения должны всегда указывать в oldstate значение, отличное от
       NULL. Эти утверждения относятся и к аргументу oldtype функции pthread_setcanceltype().

ПРИМЕРЫ

       Смотрите pthread_cancel(3).

СМОТРИТЕ ТАКЖЕ

       pthread_cancel(3), pthread_cleanup_push(3), pthread_testcancel(3), pthreads(7)

ПЕРЕВОД

       Русский    перевод    этой    страницы    руководства    разработал(и)    Alexey,     Azamat     Hackimov
       <azamat.hackimov@gmail.com>,       kogamatranslator49       <r.podarov@yandex.ru>,      Darima      Kogan
       <silverdk99@gmail.com>, Max  Is  <ismax799@gmail.com>,  Yuri  Kozlov  <yuray@komyakino.ru>,  Иван  Павлов
       <pavia00@gmail.com> и Kirill Rekhov <krekhov.dev@gmail.com>

       Этот  перевод является свободной программной документацией; он распространяется на условиях общедоступной
       лицензии GNU (GNU General Public License - GPL, https://www.gnu.org/licenses/gpl-3.0.html  версии  3  или
       более поздней) в отношении авторского права, но БЕЗ КАКИХ-ЛИБО ГАРАНТИЙ.

       Если  вы  обнаружите какие-либо ошибки в переводе этой страницы руководства, пожалуйста, сообщите об этом
       разработчику(ам)  по  его(их)  адресу(ам)  электронной  почты  или  по   адресу   списка рассылки русских
       переводчиков.

Справочные страницы Linux 6.9.1                   2 мая 2024 г.                        pthread_setcancelstate(3)