Back to index

glibc  2.9
tststack.c
Go to the documentation of this file.
00001 /* Tests for variable stack size handling.
00002    Copyright (C) 2000, 2003 Free Software Foundation, Inc.
00003    Contributed by Ulrich Drepper <drepper@redhat.com>, 2000.
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 License as
00007    published by the Free Software Foundation; either version 2.1 of the
00008    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; see the file COPYING.LIB.  If not,
00017    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018    Boston, MA 02111-1307, USA.  */
00019 
00020 #include <pthread.h>
00021 #include <stdio.h>
00022 #include <unistd.h>
00023 #include <limits.h>
00024 #include <sys/param.h>
00025 
00026 static void *f1 (void *);
00027 static void *f2 (void *);
00028 
00029 int
00030 main (void)
00031 {
00032   pthread_attr_t attr;
00033   pthread_t th1 = 0;
00034   pthread_t th2 = 0;
00035   void *res1;
00036   void *res2;
00037 
00038   pthread_attr_init (&attr);
00039   if (pthread_attr_setstacksize (&attr, MAX (70*1024, PTHREAD_STACK_MIN)) != 0)
00040     {
00041       puts ("invalid stack size");
00042       return 1;
00043     }
00044 
00045   pthread_create (&th1, NULL, f1, NULL);
00046   pthread_create (&th2, &attr, f2, NULL);
00047 
00048   pthread_join (th1, &res1);
00049   pthread_join (th2, &res2);
00050 
00051   printf ("res1 = %p\n", res1);
00052   printf ("res2 = %p\n", res2);
00053 
00054   return res1 != (void *) 1 || res2 != (void *) 2;
00055 }
00056 
00057 static void *
00058 f1 (void *parm)
00059 {
00060   printf ("This is `%s'\n", __FUNCTION__);
00061   fflush (stdout);
00062 
00063   return (void *) 1;
00064 }
00065 
00066 static void *
00067 f2 (void *parm)
00068 {
00069   printf ("This is `%s'\n", __FUNCTION__);
00070   fflush (stdout);
00071   sleep (1);
00072 
00073   return (void *) 2;
00074 }