Problem with stack size in pthreads
Hui Huang
hui.huang@eng.sun.com
Thu Jul 12 12:45:00 GMT 2001
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
More information about the Libc-alpha
mailing list