Too low PTHREAD_STACK_MIN value?
Roger Pau Monné
roger.pau at citrix.com
Tue Mar 11 17:07:36 UTC 2014
Hello,
While debugging a pthread program that sets the stack size of pthreads,
I've found out that the value PTHREAD_STACK_MIN is currently set (2048
bytes) seems to be way too low. As an example, the following simple
program will segfault:
---
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#define MALLOC_SIZE 1024
void *
foo(void *arg)
{
void *bar;
bar = malloc(MALLOC_SIZE);
assert(bar != NULL);
return (NULL);
}
int main(void)
{
pthread_t thread;
pthread_attr_t attr;
int rc, i;
rc = pthread_attr_init(&attr);
assert(rc == 0);
rc = pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN);
assert(rc == 0);
rc = pthread_create(&thread, &attr, foo, NULL);
assert(0 == rc);
rc = pthread_join(thread, NULL);
assert(0 == rc);
exit(EXIT_SUCCESS);
}
---
IMHO, PTHREAD_STACK_MIN should be set to a sane value, that allows the
thread to at least make use of libc functions.
Roger.
More information about the freebsd-current
mailing list