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

A intel TBB parallel_pipeline problem

SmallHeaven
Beginner
524 Views

Suppose I have a tbb::parallel_pipeline consisting of 3 filters with mode serial_in_order, parallel and serial_in_order resp. In the first filter's operator(), for some reason, when dealing with some data (e.g., s struct A), the A.flag == true, means it is occupied by some other thread, and the function has to wait until A.flag == false.

My question is:  what should be done? Just simply 

      while (A.flag) { }

to wait other thread make A.flag == false (Suppose A.flag can be made false later); or anything else?

Thanks a lot for any suggestion.

0 Kudos
1 Reply
Mark_L_Intel
Moderator
477 Views

If you're waiting for a condition to be met and you don't want to busy-wait, we can try std::this_thread::yield as a hint to switch to executing another thread:

 while (A->flag) {
   std::this_thread::yield();
 }

we also have tbb::task_arena::enqueue allowing to add a task to a TBB task arena in a more efficient way. 

0 Kudos
Reply