[thread] Set stack size?

Dear All, I'm not aware of a way to set the stack size for a new thread in either Boost.Thread or the proposed std::thread. Is this something that should be considered? It seems that on my 32-bit Linux box I get 8 MByte stacks by default. This allows a maximum of 512 threads per process with 32-bit addresses. Although 8 MBytes and 512 threads should be OK for most applications most of the time, it's not hard to imagine scenarios where either 8 MBytes or 512 threads is not enough. Would it be possible for the stack size to be an additional parameter to the thread constructor, with a default? (I don't think that the "native handle" in std::thread helps, since you don't have that handle until the thread has been created at which point it's too late. In any case, I guess that Windows must also have a way to set the stack size, and it would be helpful to have an OS-independent way to set it.) Regards, Phil.

Phil Endecott <spam_from_boost_dev <at> chezphil.org> writes:
I'm not aware of a way to set the stack size for a new thread in either Boost.Thread or the proposed std::thread. Is this something that should be considered?
It's certainly something that could be considered. It would have to be considered a hint rather than a guaranteed value, as it's an optional feature in POSIX, and the value is rounded in Windows. Anthony

Phil Endecott wrote:
I'm not aware of a way to set the stack size for a new thread in either Boost.Thread or the proposed std::thread. Is this something that should be considered?
It seems that on my 32-bit Linux box I get 8 MByte stacks by default.
I can't find a way to specify it in the pthread API. Since those are kernel threads, which are handled the same way as processes on linux, I suppose the same values as processes is used. The stack starts at 8 MB and can grow indefinitely as needed. (I don't think it is ever freed btw) If we used user threads, we could have full controls over those things.

Mathias Gaunard <mathias.gaunard@ens-lyon.org> writes:
Phil Endecott wrote:
I'm not aware of a way to set the stack size for a new thread in either Boost.Thread or the proposed std::thread. Is this something that should be considered?
It seems that on my 32-bit Linux box I get 8 MByte stacks by default.
I can't find a way to specify it in the pthread API.
pthread_attr_setstacksize Anthony -- Anthony Williams Just Software Solutions Ltd - http://www.justsoftwaresolutions.co.uk Registered in England, Company Number 5478976. Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL
participants (3)
-
Anthony Williams
-
Mathias Gaunard
-
Phil Endecott