Search code examples
c++tbb

TBB: What is a master thread?


In the docs for TBB, there is a note about reserving slots for 'master' threads in an arena:

https://www.threadingbuildingblocks.org/docs/help/reference/task_scheduler/task_arena_cls.html

A master thread can join any thread 'slot' in an arena, but worker threads cannot join the slot reserved for a master thread. Also, a task arena is allowed more than one master slot. So far so good. What is not clear to me, is what exactly does being a master thread entail? Is it "just" the main application thread? If so, how can there be more than one master thread?


Solution

  • Conceptually, the term "master thread" refers to any application thread that starts a parallel job. In contrast, a "worker thread" is a TBB-created thread which helps master threads process their job.

    Specifically for task_arena, master threads submit jobs via the public API of the class, while worker threads join an arena through the internal interface.

    A worker thread that joined an arena from inside can also become a master thread in another arena, in case a task it executes in the first arena calls task_arena::execute().