Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

Mutex question

jovanslobenovic
Beginner
246 Views
I try to build some producer-consumer application in tbb. Earlier I use WaitForSingleObject and Release semaphore function from windows api to synchronization threads. My question is how I can synchronize tbb tasks with mutex and lock?
Is this possible at all? Or there is some other techniquefor this...
Thank you in advance...
0 Kudos
3 Replies
RafSchietekat
Valued Contributor III
246 Views
The idea is that you should express all blocking dependencies (excluding predictably short waits) as parent-child relationships between tasks and let the task scheduler figure them out. Otherwise the task scheduler will not know what is going on and leave a hardware thread otherwise unused while the software thread that should be running on it is blocked waiting. If you do have such requirements, the most straightforward approach is to do those things outside of TBB in a dedicated thread (despite the name, tbb::tbb_thread is merely an API to such a thread). But feel free to experiment: it's not always black or white.

(Added) Relating to the title of this thread, "Mutex question": those would be the predictably short waits that I mentioned, for which TBB provides several types of mutexes.
0 Kudos
jovanslobenovic
Beginner
246 Views
Thank you Raf for fast answer. Can you tell me where I can learn more about parent-child relationships?
0 Kudos
RafSchietekat
Valued Contributor III
246 Views
Read the chapters about the Task Scheduler in the Tutorial and the Reference Manual. Broadly speaking, a parent task becomes eligible for execution only when its children have finished, so expressing dependencies that way is a natural fit for the scheduler.
0 Kudos
Reply