Safe Stack Size?

I am writing some code that generates quite a lot of threads (about 512 at the moment, but in the future it may become higher). Each of the threads performs only a small number of operations, so I want the overhead of having the threads hosted on the system to be minimal.

I set the stack size with pthread_attr_setstacksize(), and I can get the minimum allowable stack size from PTHREAD_STACK_MIN. But my question is: Is it safe to use PTHREAD_STACK_MINfor thread stack size? . How can I calculate how much stack I need? Are there any hidden overheads that I will need to add to my calculations?

Also, are there any other methods that can be used to reduce the load on threads in the system?

+5
source share
3 answers

Reducing the size of the thread stack will not reduce overhead (not in terms of CPU usage, memory usage, or performance). Your only limit in this regard is the total available virtual address space provided by threads on your platform.

I would use the default stack size until there are problems on the platform (if that happens at all). Then minimize stack usage if and when problems arise. However, this will lead to real performance problems, since you will need to hack the heap, or develop a flow-dependent distribution elsewhere.

Hidden overhead may include:

  • , VLA, alloca() .
  • , , factory .. , , ++, .
  • .. .
  • . - , , boost::bind, , , .

, , . Pthreads ; LWP .

:

+4

, . , , , . 10 , , 12 . , .

, , , . Visual Studio . , , , . .

+7

, , , ..

, . .

+5

All Articles