Back to index

glibc  2.9
tst-timer2.c
Go to the documentation of this file.
00001 /* Test for crashing bugs when trying to create too many timers.  */
00002 
00003 #include <stdio.h>
00004 #include <time.h>
00005 #include <signal.h>
00006 #include <sys/time.h>
00007 #include <sys/resource.h>
00008 #include <unistd.h>
00009 
00010 #if _POSIX_THREADS
00011 # include <pthread.h>
00012 
00013 void
00014 thread (union sigval arg)
00015 {
00016   puts ("Timeout");
00017 }
00018 
00019 int
00020 do_test (void)
00021 {
00022   int i, res;
00023   timer_t timerId;
00024   struct itimerspec itval;
00025   struct sigevent sigev;
00026 
00027   itval.it_interval.tv_sec = 2;
00028   itval.it_interval.tv_nsec = 0;
00029   itval.it_value.tv_sec = 2;
00030   itval.it_value.tv_nsec = 0;
00031 
00032   sigev.sigev_notify = SIGEV_THREAD;
00033   sigev.sigev_signo = SIGRTMIN;
00034   sigev.sigev_notify_function = thread;
00035   sigev.sigev_notify_attributes = 0;
00036   sigev.sigev_value.sival_ptr = (void *) &timerId;
00037 
00038   for (i = 0; i < 100; i++)
00039     {
00040       printf ("cnt = %d\n", i);
00041 
00042       if (timer_create (CLOCK_REALTIME, &sigev, &timerId) < 0)
00043        {
00044          perror ("timer_create");
00045          continue;
00046        }
00047 
00048       res = timer_settime (timerId, 0, &itval, NULL);
00049       if (res < 0)
00050        perror ("timer_settime");
00051 
00052       res = timer_delete (timerId);
00053       if (res < 0)
00054        perror ("timer_delete");
00055     }
00056 
00057   return 0;
00058 }
00059 
00060 # define TEST_FUNCTION do_test ()
00061 #else
00062 # define TEST_FUNCTION 0
00063 #endif
00064 
00065 #include "../test-skeleton.c"