How does Intel TBB protect against stack overflows on the worker threads? In the early versions (and in the Intel TBB book) it was done by checking the depth of the tasks. To my understanding this feature was dropped. What other protection replaces it?
- let's assume that we have 1000 root-tasks, and each of these root-tasks can go down by 1000 levels (no continuation-style, just stack based spawning, like in the classic Fibonacci example)
- let's now assume that our tasks consume some stack memory, that we would fit 2000 tasks into a thread tasks, but not more
- if we have enough stack to execute 1 root-task completely on one thread, we don't have the space to execute 10 root-tasks on the same thread
How does Intel TBB prevents endless stack filling?
Thank you very much,
hello, you can increase stack size if needed. AFAIR default thread size is 1 mb for a windows application and 2 mb for tbb workers. but nobody prevents to increase it.
TBB works efficiently with the stack on its high-level algorithms but if you want to program in low level tasks you need to think how much stack you need.
Thank you very much for your answer.
Yes, indeed, I can increase the stack at any time, but I don't have any guarantee that with a fixed stack size I will not overflow given enough tasks to be executed (and a lot of stealing). In my example, I have to budget the stack for 1000*1000 tasks to make sure that I don't overflow. To my assumptions that is a 500 times bigger stack! I cannot simply say: I'll give 500MB for all my working threads,
Isn't there a mechanism already implemented in TBB for limiting the stack growth?