summaryrefslogtreecommitdiffstats
path: root/man3/pthread_cancel.3
diff options
context:
space:
mode:
Diffstat (limited to 'man3/pthread_cancel.3')
-rw-r--r--man3/pthread_cancel.336
1 files changed, 18 insertions, 18 deletions
diff --git a/man3/pthread_cancel.3 b/man3/pthread_cancel.3
index 231466119..5ff2ff8f7 100644
--- a/man3/pthread_cancel.3
+++ b/man3/pthread_cancel.3
@@ -157,66 +157,66 @@ main(): thread was canceled
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-
+\&
#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 cancelation for a while, so that we don\[aq]t
immediately react to a cancelation request. */
-
+\&
s = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
if (s != 0)
handle_error_en(s, "pthread_setcancelstate");
-
+\&
printf("%s(): started; cancelation disabled\en", __func__);
sleep(5);
printf("%s(): about to enable cancelation\en", __func__);
-
+\&
s = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
if (s != 0)
handle_error_en(s, "pthread_setcancelstate");
-
+\&
/* sleep() is a cancelation point. */
-
+\&
sleep(1000); /* Should get canceled while we sleep */
-
+\&
/* Should never get here. */
-
+\&
printf("%s(): not canceled!\en", __func__);
return NULL;
}
-
+\&
int
main(void)
{
pthread_t thr;
void *res;
int s;
-
+\&
/* Start a thread and then send it a cancelation 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("%s(): sending cancelation request\en", __func__);
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("%s(): thread was canceled\en", __func__);
else