pthread_create fails on a device with 16MB RAM

Rich Felker dalias at aerifal.cx
Sat Jan 29 21:50:11 UTC 2011


On Fri, Jan 28, 2011 at 09:31:37AM +0000, Carl Shaw wrote:
> This occurs because the default maximum stack size is usually 8MB (check
> using ulimit -s or -a at a shell prompt).
> 
> You have a number of options to change this:
> 
[...]
> 2.  Allocate your own stack memory, insert into to a thread attribute
> structure using pthread_attr_setstack() and use that when creating the
> thread with pthread_create()

This is the approach application developers should take, since some
libcs offer ridiculously large stacks (which are reserved/committed on
systems with overcommit protection!) while others offer tiny ones. A
portable program that uses nontrivial stack space needs to ensure it
will be given enough, and a program that doesn't want to waste memory
should ensure that it's not given too much.

> 3.  Patch the C library to use a more appropriate default rather than
> calling getrlimit(RLIMIT_STACK)!

This sounds like a patch that belongs in uclibc. 32k would be a
reasonable default.

Rich


More information about the uClibc mailing list