Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 11 Mar 2014 18:07:25 +0100
From:      =?ISO-8859-1?Q?Roger_Pau_Monn=E9?= <roger.pau@citrix.com>
To:        <freebsd-current@freebsd.org>
Subject:   Too low PTHREAD_STACK_MIN value?
Message-ID:  <531F42CD.8020307@citrix.com>

next in thread | raw e-mail | index | archive | help
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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?531F42CD.8020307>