Back to index

glibc  2.9
tst-stack2.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 Jakub Jelinek <jakub@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 /* Test whether it is possible to create a thread with PTHREAD_STACK_MIN
00021    stack size.  */
00022 
00023 #include <pthread.h>
00024 #include <stdlib.h>
00025 #include <stdio.h>
00026 
00027 static int seen;
00028 
00029 static void *
00030 tf (void *p)
00031 {
00032   ++seen;
00033   return NULL;
00034 }
00035 
00036 static int
00037 do_test (void)
00038 {
00039   pthread_attr_t attr;
00040   pthread_attr_init (&attr);
00041 
00042   int result = 0;
00043   int res = pthread_attr_setstacksize (&attr, PTHREAD_STACK_MIN);
00044   if (res)
00045     {
00046       printf ("pthread_attr_setstacksize failed %d\n", res);
00047       result = 1;
00048     }
00049 
00050   /* Create the thread.  */
00051   pthread_t th;
00052   res = pthread_create (&th, &attr, tf, NULL);
00053   if (res)
00054     {
00055       printf ("pthread_create failed %d\n", res);
00056       result = 1;
00057     }
00058   else
00059     {
00060       res = pthread_join (th, NULL);
00061       if (res)
00062        {
00063          printf ("pthread_join failed %d\n", res);
00064          result = 1;
00065        }
00066     }
00067 
00068   if (seen != 1)
00069     {
00070       printf ("seen %d != 1\n", seen);
00071       result = 1;
00072     }
00073 
00074   return result;
00075 }
00076 
00077 
00078 #define TEST_FUNCTION do_test ()
00079 #include "../test-skeleton.c"