Back to index

glibc  2.9
bug-sleep.c
Go to the documentation of this file.
00001 /* PR libc/4005 */
00002 #include <pthread.h>
00003 #include <stdio.h>
00004 #include <unistd.h>
00005 #include <time.h>
00006 
00007 void *
00008 run_thread (void *a)
00009 {
00010   while (1)
00011     {
00012       sleep (10);
00013     }
00014   return 0;
00015 }
00016 
00017 int
00018 main (void)
00019 {
00020   pthread_t thr;
00021   void *result;
00022   alarm (4);
00023   printf ("Starting thread.\n");
00024   pthread_create (&thr, 0, run_thread, 0);
00025   sleep (2);
00026   printf ("Canceling thread.\n");
00027   pthread_cancel (thr);
00028   pthread_join (thr, &result);
00029   if (result == PTHREAD_CANCELED)
00030     printf ("Thread canceled.\n");
00031   else
00032     printf ("Thread exited.\n");
00033   return 0;
00034 }