Search code examples
c++multithreadingthreadpooltbb

TBB parallel_for threadpool


I'm trying to learn a bit about TBB and I have a doubt that I haven't been able to solved it.

Afaik, TBB uses a threadpool so it doesn't need to create threads all the time. If you use tbb::parallel_for, does it use this threadpool or does it create new threads? If it uses the threadpool, how is the threadpool created? There is no need to do any call to create the threadpool or configure it. Does it creates the threadpool on the first parallel invocation?


Solution

  • TBB has internal thread pool and it needs some time to create threads on a first tbb's algorithm call (to "warm-up" library). You didn't need to create it explicitly. 1 is a quite old post but it has a clue how it working under the hood(or it was some time ago)

    Also if you need to specify some limits for threads count or stack size of worker threads for a part of your algorithm you can use task_scheduler_init but it not hard-bounded with a real thread count. Just FYI.