diff options
author | Siddhesh Poyarekar <siddhesh@redhat.com> | 2013-03-01 14:15:39 +0530 |
---|---|---|
committer | Siddhesh Poyarekar <siddhesh@redhat.com> | 2013-03-01 14:15:39 +0530 |
commit | e23872c8db1fb26713b9c15b12686ac7a0077576 (patch) | |
tree | a7fa040afb53ba1f5bd98bb33f214aa32e3729b8 /nptl/tst-pthread-stack-env.c | |
parent | fd6cdc6da490616f4d381f4d44f03d61f64da2ba (diff) | |
download | glibc-e23872c8db1fb26713b9c15b12686ac7a0077576.zip glibc-e23872c8db1fb26713b9c15b12686ac7a0077576.tar.gz glibc-e23872c8db1fb26713b9c15b12686ac7a0077576.tar.bz2 |
Set default stack size from program environment
New environment variable GLIBC_PTHREAD_DEFAULT_STACKSIZE to do this.
Diffstat (limited to 'nptl/tst-pthread-stack-env.c')
-rw-r--r-- | nptl/tst-pthread-stack-env.c | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/nptl/tst-pthread-stack-env.c b/nptl/tst-pthread-stack-env.c new file mode 100644 index 0000000..09f0304 --- /dev/null +++ b/nptl/tst-pthread-stack-env.c @@ -0,0 +1,77 @@ +/* Verify that pthreads uses the default thread stack size set with the + GLIBC_PTHREAD_DEFAULT_STACKSIZE environment variable. + Copyright (C) 2013 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#include <pthread.h> +#include <stdio.h> +#include <string.h> + +/* It is possible that the default stack size somehow ends up being 1MB, thus + giving a false positive. The ideal way to test this would be to get the + current stacksize fork a process with the default stack size set to + something different to the current stack size and verify in the child + process that the environment variable worked. */ +#define STACKSIZE 1024 * 1024L + +void * +thr (void *u) +{ + size_t stacksize, guardsize; + pthread_attr_t attr; + pthread_getattr_np (pthread_self (), &attr); + + pthread_attr_getstacksize (&attr, &stacksize); + pthread_attr_getguardsize (&attr, &guardsize); + + /* FIXME once guardsize is excluded from stacksize. */ + if (stacksize - guardsize != STACKSIZE) + { + printf ("Stack size is %zu, should be %zu\n", stacksize - guardsize, + STACKSIZE); + return (void *) 1; + } + + return NULL; +} + +int +do_test (int argc, char **argv) +{ + pthread_t t; + void *thr_ret; + int ret; + + if ((ret = pthread_create (&t, NULL, thr, NULL)) != 0) + { + printf ("thread create failed: %s\n", strerror (ret)); + return 1; + } + + if ((ret = pthread_join (t, &thr_ret)) != 0) + { + printf ("join failed: %s\n", strerror (ret)); + return 1; + } + + if (thr_ret != NULL && thr_ret != PTHREAD_CANCELED) + return 1; + + return 0; +} + +#include "../test-skeleton.c" |