views:

41

answers:

1

I use pthreads_attr_getthreadsizes() to get default stack size of one thread, 8MB on my machine.

But when I create 8 threads and allocate a very large stack size to them, say hundreds of MB, the program crash.

So, I guess, shall

("Number of threads" * "stack size per thread") < a constant value (e.g. virtual memory size)

?

+1  A: 

The short answer is "Yes".

The longer answer is that all of your threads share one virtual address space, and userspace-usable part of this space must be therefore be large enough to contain all thread stacks (as well as the code, static data, heap, libraries and any miscellaneous mappings).

Multi-hundred-megabyte stacks are a good indication that You're Doing It Wrong, as they say in the classics.

caf
caf, thanks, can you suggest some classics?
David
All I meant was that the runtime stack is not generally suitable for storing enormous data structures; you should be using heap allocation for such things.
caf
caf, thank you!
David