Switching off the task stealing

Switching off the task stealing


I would like to know if it is possible to switch the task stealing off when using TBB ?
It appears to be activated by default and I need to switch it off to perform specific tests ....
I looked into the official book and found nothing related to this.

Did somebody already try something like that ?

Thanks a lot !

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Hi, yes, it is possible. Include task_scheduler_init.h header file and in your code before you run anything related to TBB create a task_scheduler_init object and pass 1 as an argument to the constructor (more info in reference manual).

tbb::task_scheduler_init init(1);

This will effectively turn off implicit TBB multi-threading for your application, only one TBB worker thread will be created, the work will be serialized, the tasks will be created in this single thread's task pool and will never be stolen, just taken out and executed. Unfortunately serialization is the only way here, because task stealing is the only mechanism in TBB to share work between threads, so having multiple threads with no stealing means having really just one thread.Note: if you explicitly create other std::threads and run several algorithms in parallel, I think there still will be stealing between these master threads and task_scheduler_init will not help.

Thanks for your help,

Leave a Comment

Please sign in to add a comment. Not a member? Join today