This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Re: Problem with stack size in pthreads
On Fri, Jul 13, 2001 at 11:49:33PM -0700, H . J . Lu wrote:
> On Thu, Jul 12, 2001 at 12:55:56PM -0700, Hui Huang wrote:
> > Ulrich Drepper wrote:
> >
> > > Andreas Jaeger <aj@suse.de> writes:
> > >
> > >
> > >>>This is not supposed to happen because we made a setrlimit() call.
> > >>>Testcase?
> > >>>
> > >>JDK :-(
> > >>
> > >
> > > Right! Nice joke.
> > >
> > >
> >
> > Why do you think it's a joke? It's a bug.
> >
> > Call getrlimit(RLIMIT_STACK, &rlim) in any C program and run it with
> > "LD_ASSUME_KERNEL=2.2.5", you'll see stack limit is not correctly set.
> > I assume you want to set stack limit to STACK_SIZE-pagesize = 2040K,
> > but no, it's not set to that value.
> >
>
> That is because __pthread_init_max_stacksize is not called in your
> testcase. Should we always call __pthread_init_max_stacksize for
> pthreads, something like the patch encloded here?
>
>
Any comments on this patch?
H.J.
----
2001-07-14 H.J. Lu <hjl@gnu.org>
* attr.c (__pthread_attr_setstacksize): Don't call
__pthread_init_max_stacksize.
* pthread.c (__pthread_init_max_stacksize): Renamed to ...
(pthread_init_max_stacksize): This. Make it static.
(pthread_initialize): Call pthread_init_max_stacksize here.
(__pthread_initialize_manager): Don't call
__pthread_init_max_stacksize.
Index: linuxthreads/attr.c
===================================================================
RCS file: /work/cvs/gnu/glibc/linuxthreads/attr.c,v
retrieving revision 1.1.1.11
diff -u -p -r1.1.1.11 attr.c
--- linuxthreads/attr.c 2001/06/18 21:41:08 1.1.1.11
+++ linuxthreads/attr.c 2001/07/14 15:31:25
@@ -188,12 +188,7 @@ link_warning (pthread_attr_getstackaddr,
int __pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize)
{
#ifdef FLOATING_STACKS
- /* We have to check against the maximum allowed stack size. This is no
- problem if the manager is already started and we determined it. If
- this hasn't happened, we have to find the limit outself. */
- if (__pthread_max_stacksize == 0)
- __pthread_init_max_stacksize ();
-
+ /* We have to check against the maximum allowed stack size. */
if (stacksize > __pthread_max_stacksize)
return EINVAL;
#else
Index: linuxthreads/pthread.c
===================================================================
RCS file: /work/cvs/gnu/glibc/linuxthreads/pthread.c,v
retrieving revision 1.1.1.21
diff -u -p -r1.1.1.21 pthread.c
--- linuxthreads/pthread.c 2001/06/18 21:41:11 1.1.1.21
+++ linuxthreads/pthread.c 2001/07/14 15:41:05
@@ -224,6 +224,7 @@ static void pthread_atexit_retcode(void
static void pthread_handle_sigcancel(int sig);
static void pthread_handle_sigrestart(int sig);
static void pthread_handle_sigdebug(int sig);
+static void pthread_init_max_stacksize (void);
/* CPU clock handling. */
#if HP_TIMING_AVAIL
@@ -408,6 +409,11 @@ static void pthread_initialize(void)
/* If already done (e.g. by a constructor called earlier!), bail out */
if (__pthread_initial_thread_bos != NULL) return;
+
+ /* We need to initialize it here to make sure that no pthreads
+ applications will exceed the maximum allowed stack size. */
+ pthread_init_max_stacksize ();
+
#ifdef TEST_FOR_COMPARE_AND_SWAP
/* Test if compare-and-swap is available */
__pthread_has_cas = compare_and_swap_is_available();
@@ -470,7 +476,7 @@ void __pthread_initialize(void)
pthread_initialize();
}
-void __pthread_init_max_stacksize(void)
+static void pthread_init_max_stacksize(void)
{
struct rlimit limit;
size_t max_stack;
@@ -514,8 +520,6 @@ int __pthread_initialize_manager(void)
__dso_handle);
#endif
- if (__pthread_max_stacksize == 0)
- __pthread_init_max_stacksize ();
/* If basic initialization not done yet (e.g. we're called from a
constructor run before our constructor), do it now */
if (__pthread_initial_thread_bos == NULL) pthread_initialize();
Index: linuxthreads/internals.h
===================================================================
RCS file: /work/cvs/gnu/glibc/linuxthreads/internals.h,v
retrieving revision 1.1.1.16
diff -u -p -r1.1.1.16 internals.h
--- linuxthreads/internals.h 2001/06/18 21:41:10 1.1.1.16
+++ linuxthreads/internals.h 2001/07/14 15:31:35
@@ -441,7 +441,6 @@ extern void __pthread_do_exit (void *ret
__attribute__ ((__noreturn__));
extern void __pthread_destroy_specifics (void);
extern void __pthread_perform_cleanup (char *currentframe);
-extern void __pthread_init_max_stacksize (void);
extern int __pthread_initialize_manager (void);
extern void __pthread_message (char * fmt, ...);
extern int __pthread_manager (void *reqfd);