.\" -*- coding: UTF-8 -*- .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk .\" .\" .\" %%%LICENSE_START(VERBATIM) .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH PTHREAD_CANCEL 3 "9 juin 2020" Linux "Manuel du programmeur Linux" .SH NOM pthread_cancel \- Envoyer une requête d'annulation à un thread .SH SYNOPSIS .nf \fB#include \fP .PP \fBint pthread_cancel(pthread_t \fP\fIthread\fP\fB);\fP .PP Compiler et éditer les liens avec \fI\-pthreads\fP. .fi .SH DESCRIPTION La fonction \fBpthread_cancel\fP() envoie une requête d'annulation au thread \fIthread\fP. Si et quand le thread ciblé réagit à la requête d'annulation dépend de deux attributs qui sont sous le contrôle de ce thread\ : son état d'annulation (\fIstate\fP) et son mode d'annulation (\fItype\fP). .PP L'état d'annulation d'un thread, déterminé par \fBpthread_setcancelstate\fP(3), peut être activé (\fIenabled\fP), c'est le défaut pour les nouveaux threads, ou désactivé (\fIdisabled\fP). Si un thread désactive l'annulation, alors une demande d'annulation restera dans la file d'attente jusqu'à ce que le thread active l'annulation. Si un thread active l'annulation, alors son mode d'annulation va déterminer le moment où cette annulation est effectuée. .PP Le mode d'annulation d'un thread, déterminé par \fBpthread_setcanceltype\fP(3), peut être asynchrone (\fIasynchronous\fP) ou retardée (\fIdeferred\fP), qui est le mode par défaut pour les nouveaux threads. Un mode d'annulation asynchrone signifie que le thread peut être annulé à tout moment (d'ordinaire immédiatement, mais ce n'est pas garanti). Un mode d'annulation retardé signifie que l'annulation peut être retardée jusqu'à ce que le thread appelle une fonction qui est un point d'annulation (\fIcancellation point\fP). Une liste des fonctions qui sont ou peuvent être des points d'annulation est donnée dans \fBpthreads\fP(7). .PP Quand une requête d'annulation est traitée, les étapes suivantes sont effectuées pour \fIthread\fP (dans cet ordre)\ : .IP 1. 3 Les gestionnaires de nettoyage sont dépilés (dans l'ordre inverse dans lequel ils ont été empilés) et appelés (consultez \fBpthread_cleanup_push\fP(3)). .IP 2. Les destructeurs de données spécifiques aux threads sont appelés, dans un ordre non déterminé (consultez \fBpthread_key_create\fP(3)). .IP 3. Le thread s'est terminé (consultez \fBpthread_exit\fP(3)). .PP Les étapes ci\-dessus sont effectuées de manière asynchrone par rapport à l'appel à \fBpthread_cancel\fP(). La valeur de retour de \fBpthread_cancel\fP() ne fait qu'informer l'appelant si une requête d'annulation a été correctement mise en file d'attente. .PP Après qu'un thread annulé s'est terminé, une demande de jointure par \fBpthread_join\fP(3) renvoie \fBPTHREAD_CANCELED\fP comme état de sortie du thread. Il faut noter que joindre un thread est la seule manière de savoir si une annulation a terminé. .SH "VALEUR RENVOYÉE" En cas de réussite, \fBpthread_cancel\fP() renvoie 0\ ; en cas d'erreur, elle renvoie un numéro d'erreur non nul. .SH ERREURS .TP \fBESRCH\fP .\" .SH VERSIONS .\" Available since glibc 2.0 Aucun fil d’exécution avec pour identifiant \fIthread\fP n'a pu être trouvé. .SH ATTRIBUTS Pour une explication des termes utilisés dans cette section, consulter \fBattributes\fP(7). .TS allbox; lb lb lb l l l. Interface Attribut Valeur T{ \fBpthread_cancel\fP() T} Sécurité des threads MT\-Safe .TE .sp 1 .SH CONFORMITÉ POSIX.1\-2001, POSIX.1\-2008. .SH NOTES Sous Linux, l'annulation est implémentée par des signaux. Avec l'implémentation NPTL, le premier signal temps\-réel (c'est\-à\-dire le signal 32) est utilisé dans ce but. Avec LinuxThreads, le second signal temps\-réel est utilisé, si les signaux temps\-réels sont disponibles, sinon \fBSIGUSR2\fP est utilisé à la place. .SH EXEMPLES Le programme ci\-dessous crée un thread puis l'annule. Le thread principal joint le thread annulé pour vérifier que son état de sortie était bien \fBPTHREAD_CANCELED\fP. La session suivante montre un exemple d'exécution\ : .PP .in +4n .EX $ ./a.out thread_func(): started; cancellation disabled main(): sending cancellation request thread_func(): about to enable cancellation main(): thread was canceled .EE .in .SS "Source du programme" \& .EX #include #include #include #include #include #define handle_error_en(en, msg) \e do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0) static void * thread_func(void *ignored_argument) { int s; /* Disable cancellation for a while, so that we don\(aqt immediately react to a cancellation request */ s = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); if (s != 0) handle_error_en(s, "pthread_setcancelstate"); printf("thread_func(): started; cancellation disabled\en"); sleep(5); printf("thread_func(): about to enable cancellation\en"); s = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); if (s != 0) handle_error_en(s, "pthread_setcancelstate"); /* sleep() is a cancellation point */ sleep(1000); /* Should get canceled while we sleep */ /* Should never get here */ printf("thread_func(): not canceled!\en"); return NULL; } int main(void) { pthread_t thr; void *res; int s; /* Start a thread and then send it a cancellation request */ s = pthread_create(&thr, NULL, &thread_func, NULL); if (s != 0) handle_error_en(s, "pthread_create"); sleep(2); /* Give thread a chance to get started */ printf("main(): sending cancellation request\en"); s = pthread_cancel(thr); if (s != 0) handle_error_en(s, "pthread_cancel"); /* Join with thread to see what its exit status was */ s = pthread_join(thr, &res); if (s != 0) handle_error_en(s, "pthread_join"); if (res == PTHREAD_CANCELED) printf("main(): thread was canceled\en"); else printf("main(): thread wasn\(aqt canceled (shouldn\(aqt happen!)\en"); exit(EXIT_SUCCESS); } .EE .SH "VOIR AUSSI" .ad l .nh \fBpthread_cleanup_push\fP(3), \fBpthread_create\fP(3), \fBpthread_exit\fP(3), \fBpthread_join\fP(3), \fBpthread_key_create\fP(3), \fBpthread_setcancelstate\fP(3), \fBpthread_setcanceltype\fP(3), \fBpthread_testcancel\fP(3), \fBpthreads\fP(7) .SH COLOPHON Cette page fait partie de la publication\ 5.10 du projet \fIman\-pages\fP Linux. Une description du projet et des instructions pour signaler des anomalies et la dernière version de cette page peuvent être trouvées à l'adresse \%https://www.kernel.org/doc/man\-pages/. .PP .SH TRADUCTION La traduction française de cette page de manuel a été créée par Christophe Blaess , Stéphan Rafin , Thierry Vignaud , François Micaux, Alain Portal , Jean-Philippe Guérard , Jean-Luc Coulon (f5ibh) , Julien Cristau , Thomas Huriaux , Nicolas François , Florentin Duneau , Simon Paillard , Denis Barbier , David Prévot et Frédéric Hantrais . .PP Cette traduction est une documentation libre ; veuillez vous reporter à la .UR https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License version 3 .UE concernant les conditions de copie et de distribution. Il n'y a aucune RESPONSABILITÉ LÉGALE. .PP Si vous découvrez un bogue dans la traduction de cette page de manuel, veuillez envoyer un message à .MT debian-l10n-french@lists.debian.org .ME .