Posts Tagged ‘maximum thread number’

pthreads – Some useful links and solution for maximum thread number

July 21, 2009

Manual Reference Pages (including a list of functions that are not thread-safe)

Tutorial on pthreads

And if you wonder why you cannot create more than X threads on your system (for me this was always 382), this forum provides a solution.

Basically, the problem is that each thread created will occupy space for its stack. On my system, the default thread stack size is 8MB. Therefore, after 382, I simply run out of space.

Solution: Change the stack size to a smaller value, unless you really need 8MB.

pthread_attr_t tattr;
size_t size;
size = PTHREAD_STACK_MIN + WHAT_ELSE_YOU_NEED;
pthread_attr_init(&tattr);
pthread_attr_setstacksize(&tattr, size);

Another interesting page on pthreads is this.

Advertisements