This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Problem with stack size in pthreads


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.

If you want a more elaborate testcase, here is one:

#include <sys/time.h>
#include <sys/resource.h>
#include <unistd.h>
#include <pthread.h>
#include <signal.h>

pthread_key_t key;

int foo(void)
{
    char ch;
    char * p = &ch;
    int val;

    if (p < 0xc0000000 - 6 * 1024 * 1024) {
         val = (int)pthread_getspecific(key);
         if (val != 95) return 2;
         else return 0;
    }
    return foo();
}

int main(void)
{
   int rslt;
   struct rlimit rlim;
   getrlimit(RLIMIT_STACK, &rlim);
   printf("rlim_cur = %dk, rlim_max = %dk\n", rlim.rlim_cur/1024, 
rlim.rlim_max/1024);
   pthread_key_create(&key, NULL);
   pthread_setspecific(key, (void *)95);
   rslt = foo();
   printf("rslt = %d (should be 0)\n", rslt);
   return rslt;
}

When the initial thread stack exceeds 6M, pthread_getspecific() will
return invalid value.

regards,
-hui


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]