Back to index

glibc  2.9
tst-kill4.c
Go to the documentation of this file.
00001 /* Copyright (C) 2003, 2006 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 <unistd.h>
00026 
00027 
00028 static void *
00029 tf (void *a)
00030 {
00031   return NULL;
00032 }
00033 
00034 
00035 int
00036 do_test (void)
00037 {
00038   pthread_attr_t at;
00039   if (pthread_attr_init (&at) != 0)
00040     {
00041       puts ("attr_create failed");
00042       exit (1);
00043     }
00044 
00045   /* Limit thread stack size, because if it is too large, pthread_join
00046      will free it immediately rather than put it into stack cache.  */
00047   if (pthread_attr_setstacksize (&at, 2 * 1024 * 1024) != 0)
00048     {
00049       puts ("setstacksize failed");
00050       exit (1);
00051     }
00052 
00053   pthread_t th;
00054   if (pthread_create (&th, &at, tf, NULL) != 0)
00055     {
00056       puts ("create failed");
00057       exit (1);
00058     }
00059 
00060   pthread_attr_destroy (&at);
00061 
00062   if (pthread_join (th, NULL) != 0)
00063     {
00064       puts ("join failed");
00065       exit (1);
00066     }
00067 
00068   /* The following only works because we assume here something about
00069      the implementation.  Namely, that the memory allocated for the
00070      thread descriptor is not going away, that the the TID field is
00071      cleared and therefore the signal is sent to process 0, and that
00072      we can savely assume there is no other process with this ID at
00073      that time.  */
00074   int e = pthread_kill (th, 0);
00075   if (e == 0)
00076     {
00077       puts ("pthread_kill succeeded");
00078       exit (1);
00079     }
00080   if (e != ESRCH)
00081     {
00082       puts ("pthread_kill didn't return ESRCH");
00083       exit (1);
00084     }
00085 
00086   return 0;
00087 }
00088 
00089 
00090 #define TEST_FUNCTION do_test ()
00091 #include "../test-skeleton.c"