Back to index

glibc  2.9
tst-eintr1.c
Go to the documentation of this file.
00001 /* Copyright (C) 2003 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003    Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <errno.h>
00021 #include <pthread.h>
00022 #include <signal.h>
00023 #include <stdio.h>
00024 #include <stdlib.h>
00025 #include <string.h>
00026 
00027 #include "eintr.c"
00028 
00029 
00030 static void *
00031 tf2 (void *arg)
00032 {
00033   return arg;
00034 }
00035 
00036 
00037 static void *
00038 tf1 (void *arg)
00039 {
00040   while (1)
00041     {
00042       pthread_t th;
00043 
00044       int e = pthread_create (&th, NULL, tf2, NULL);
00045       if (e != 0)
00046        {
00047          if (e == EINTR)
00048            {
00049              puts ("pthread_create returned EINTR");
00050              exit (1);
00051            }
00052 
00053          char buf[100];
00054          printf ("tf1: pthread_create failed: %s\n",
00055                 strerror_r (e, buf, sizeof (buf)));
00056          exit (1);
00057        }
00058 
00059       e = pthread_join (th, NULL);
00060       if (e != 0)
00061        {
00062          if (e == EINTR)
00063            {
00064              puts ("pthread_join returned EINTR");
00065              exit (1);
00066            }
00067 
00068          char buf[100];
00069          printf ("tf1: pthread_join failed: %s\n",
00070                 strerror_r (e, buf, sizeof (buf)));
00071          exit (1);
00072        }
00073     }
00074 }
00075 
00076 
00077 static int
00078 do_test (void)
00079 {
00080   setup_eintr (SIGUSR1, NULL);
00081 
00082   int i;
00083   for (i = 0; i < 10; ++i)
00084     {
00085       pthread_t th;
00086       int e = pthread_create (&th, NULL, tf1, NULL);
00087       if (e != 0)
00088        {
00089          char buf[100];
00090          printf ("main: pthread_create failed: %s\n",
00091                 strerror_r (e, buf, sizeof (buf)));
00092          exit (1);
00093        }
00094     }
00095 
00096   (void) tf1 (NULL);
00097   /* NOTREACHED */
00098 
00099   return 0;
00100 }
00101 
00102 #define EXPECTED_SIGNAL SIGALRM
00103 #define TIMEOUT 3
00104 #define TEST_FUNCTION do_test ()
00105 #include "../test-skeleton.c"