* malloc/mcheck.c (reallochook): If size==0, free the block.
[glibc/pb-stable.git] / rt / tst-timer3.c
blob8113f6690343132eaf1768c2ac6702087680a649
1 /* Test for bogus per-thread deletion of timers. */
3 #include <stdio.h>
4 #include <error.h>
5 #include <time.h>
6 #include <signal.h>
7 #include <stdint.h>
8 #include <string.h>
9 #include <sys/time.h>
10 #include <sys/resource.h>
11 #include <unistd.h>
12 #if _POSIX_THREADS
13 # include <pthread.h>
16 /* Creating timers in another thread should work too. */
17 static void *
18 do_timer_create (void *arg)
20 struct sigevent *const sigev = arg;
21 timer_t *const timerId = sigev->sigev_value.sival_ptr;
22 if (timer_create (CLOCK_REALTIME, sigev, timerId) < 0)
24 printf ("timer_create: %m\n");
25 return NULL;
27 return timerId;
31 static int
32 do_test (void)
34 int i, res;
35 timer_t timerId;
36 struct itimerspec itval;
37 struct sigevent sigev;
39 itval.it_interval.tv_sec = 2;
40 itval.it_interval.tv_nsec = 0;
41 itval.it_value.tv_sec = 2;
42 itval.it_value.tv_nsec = 0;
44 sigev.sigev_notify = SIGEV_SIGNAL;
45 sigev.sigev_signo = SIGALRM;
46 sigev.sigev_value.sival_ptr = (void *) &timerId;
48 for (i = 0; i < 100; i++)
50 printf ("cnt = %d\n", i);
52 pthread_t thr;
53 res = pthread_create (&thr, NULL, &do_timer_create, &sigev);
54 if (res)
56 printf ("pthread_create: %s\n", strerror (res));
57 continue;
59 void *val;
60 res = pthread_join (thr, &val);
61 if (res)
63 printf ("pthread_join: %s\n", strerror (res));
64 continue;
66 if (val == NULL)
67 continue;
69 res = timer_settime (timerId, 0, &itval, NULL);
70 if (res < 0)
71 printf ("timer_settime: %m\n");
73 res = timer_delete (timerId);
74 if (res < 0)
75 printf ("timer_delete: %m\n");
78 return 0;
81 # define TEST_FUNCTION do_test ()
82 #else
83 # define TEST_FUNCTION 0
84 #endif
86 #include "../test-skeleton.c"