This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Maximum stacksize for user-defined threads necessary?
- From: Wolfram Gloger <Wolfram dot Gloger at dent dot med dot uni-muenchen dot de>
- To: libc-alpha at sources dot redhat dot com
- Date: Mon, 9 Sep 2002 17:00:33 +0200 (MDT)
- Subject: Maximum stacksize for user-defined threads necessary?
Hi,
Is there any reason why we restrict the maximum size for user-defined
stacks in LinuxThreads? I couldn't see one..
2002-09-09 Wolfram Gloger <wg@malloc.de>
* attr.c (__pthread_attr_setstack): Don't restrict maximum
stacksize.
* Examples/ex17.c (main): Try a really large user-defined stack
first, then a smaller one if not enough memory.
--- attr.c.orig Sun Feb 24 03:27:18 2002
+++ attr.c Mon Sep 9 16:42:24 2002
@@ -221,24 +221,20 @@
int __pthread_attr_setstack (pthread_attr_t *attr, void *stackaddr,
size_t stacksize)
{
- int err;
-
if ((((uintptr_t) stackaddr)
- & (__alignof__ (struct _pthread_descr_struct) - 1)) != 0)
- err = EINVAL;
- else
- err = __pthread_attr_setstacksize (attr, stacksize);
- if (err == 0)
- {
+ & (__alignof__ (struct _pthread_descr_struct) - 1)) != 0 ||
+ stacksize < PTHREAD_STACK_MIN)
+ return EINVAL;
+
+ attr->__stacksize = stacksize;
#ifndef _STACK_GROWS_UP
- attr->__stackaddr = (char *) stackaddr + stacksize;
+ attr->__stackaddr = (char *) stackaddr + stacksize;
#else
- attr->__stackaddr = stackaddr;
+ attr->__stackaddr = stackaddr;
#endif
- attr->__stackaddr_set = 1;
- }
+ attr->__stackaddr_set = 1;
- return err;
+ return 0;
}
weak_alias (__pthread_attr_setstack, pthread_attr_setstack)
--- Examples/ex17.c.orig Sun Aug 25 10:38:22 2002
+++ Examples/ex17.c Mon Sep 9 16:55:58 2002
@@ -15,7 +15,10 @@
return NULL;
}
-#define STACKSIZE 0x100000
+/* Try a really large stack first. */
+#define STACKSIZE0 0x1000000
+/* Fallback if not enough memory. */
+#define STACKSIZE1 0x100000
int
main (void)
@@ -24,20 +27,27 @@
pthread_attr_t attr;
int status;
void *stack, *stack2;
- size_t stacksize;
+ size_t set_stacksize = STACKSIZE0, stacksize;
pthread_attr_init (&attr);
- stack = mmap (NULL, STACKSIZE,
+ stack = mmap (NULL, set_stacksize,
PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (stack == MAP_FAILED)
{
- perror ("mmap failed");
- return 1;
+ set_stacksize = STACKSIZE1;
+ stack = mmap (NULL, set_stacksize,
+ PROT_READ | PROT_WRITE | PROT_EXEC,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ if (stack == MAP_FAILED)
+ {
+ perror ("mmap failed");
+ return 1;
+ }
}
- status = pthread_attr_setstack (&attr, stack, STACKSIZE);
+ status = pthread_attr_setstack (&attr, stack, set_stacksize);
if (status != 0)
{
printf ("pthread_attr_setstack failed: %s\n", strerror (status));
@@ -51,11 +61,11 @@
return 1;
}
- if (stack2 != stack || stacksize != STACKSIZE)
+ if (stack2 != stack || stacksize != set_stacksize)
{
printf ("first pthread_attr_getstack returned different stack (%p,%zx)\n"
"than was set by setstack (%p,%x)\n",
- stack2, stacksize, stack, STACKSIZE);
+ stack2, stacksize, stack, set_stacksize);
return 2;
}
@@ -87,11 +97,11 @@
return 1;
}
- if (stack2 != stack || stacksize != STACKSIZE)
+ if (stack2 != stack || stacksize != set_stacksize)
{
printf ("second pthread_attr_getstack returned different stack (%p,%zx)\n"
"than was set by setstack (%p,%x)\n",
- stack2, stacksize, stack, STACKSIZE);
+ stack2, stacksize, stack, set_stacksize);
return 3;
}