1pthread_testcancel(3C) Standard C Library Functions pthread_testcancel(3C)
2
3
4
6 pthread_testcancel - create cancellation point in the calling thread
7
9 cc -mt [ flag... ] file... -lpthread [ library... ]
10 #include <pthread.h>
11
12 void pthread_testcancel(void);
13
14
16 The pthread_testcancel() function forces testing for cancellation. This
17 is useful when you need to execute code that runs for long periods
18 without encountering cancellation points; such as a library routine
19 that executes long-running computations without cancellation points.
20 This type of code can block cancellation for unacceptable long periods
21 of time. One strategy for avoiding blocking cancellation for long
22 periods, is to insert calls to pthread_testcancel() in the long-running
23 computation code and to setup a cancellation handler in the library
24 code, if required.
25
27 The pthread_testcancel() function returns void.
28
30 The pthread_testcancel() function does not return errors.
31
33 See cancellation(5) for an example of using pthread_testcancel() to
34 force testing for cancellation and a discussion of cancellation con‐
35 cepts.
36
38 See attributes(5) for descriptions of the following attributes:
39
40
41
42
43 ┌─────────────────────────────┬─────────────────────────────┐
44 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
45 ├─────────────────────────────┼─────────────────────────────┤
46 │Interface Stability │Standard │
47 ├─────────────────────────────┼─────────────────────────────┤
48 │MT-Level │MT-Safe │
49 └─────────────────────────────┴─────────────────────────────┘
50
52 Intro(3), pthread_cleanup_pop(3C), pthread_cleanup_push(3C),
53 pthread_exit(3C), pthread_join(3C), pthread_setcancelstate(3C),
54 pthread_setcanceltype(3C), setjmp(3C), attributes(5), cancellation(5),
55 condition(5), standards(5)
56
58 The pthread_testcancel() function has no effect if cancellation is dis‐
59 abled.
60
61
62 Use pthread_testcancel() with pthread_setcanceltype() called with its
63 canceltype set to PTHREAD_CANCEL_DEFERRED. The pthread_testcancel()
64 function operation is undefined if pthread_setcanceltype() was called
65 with its canceltype argument set to PTHREAD_CANCEL_ASYNCHRONOUS.
66
67
68 It is possible to kill a thread when it is holding a resource, such as
69 lock or allocated memory. If that thread has not setup a cancellation
70 cleanup handler to release the held resource, the application is "can‐
71 cel-unsafe". See attributes(5) for a discussion of Cancel-Safety,
72 Deferred-Cancel-Safety, and Asynchronous-Cancel-Safety.
73
74
75
76SunOS 5.11 23 Mar 2005 pthread_testcancel(3C)