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

how to make tbb::flow::async_node a tbb::flow::serial node ?

Marc_R_5
Beginner
581 Views

I want to use a tbb::flow::async_node to execute a function in a dedicated thread.  I have a tbb::flow::sequencer_node sending messages (in order) to an async_node but the async_node lambda function gets called in no specific order!  There does not seem to be a way to specify that the async node is tbb::flow::serial.  So the submit call to the async activity is not sequential... 

Is there a way to make an async_node submitting its messages in a tbb::flow::serial fashion ?

Thanks !

 

0 Kudos
3 Replies
Alexey-Kukanov
Employee
581 Views

Hi Marc,

Yes, serial semantics for async_node is a missing feature, and it will be added in the future.

A possible workaround is to put a limiter_node with the limit of 1 in front of the async_node. The async_node functor should then explicitly decrement the limiter after sending the data to an external thread.

0 Kudos
jimdempseyatthecove
Honored Contributor III
581 Views

This may take a little bit of fitness...

Instead of sending a functor to the async_node, send the functor into a container that contains a ring buffer of functors and is managed in a MPSC manner. On first fill condition the PushNext function (called by the producer thread) enueues the (only) ring buffer container (the this of the container) to the asynchronous task. In this manner, there is only one ring buffer and all entries go into and come out in order.

Jim Dempsey

0 Kudos
Adel_S_
Beginner
581 Views

thank you Alexey Kukanov and Jim Dempsey

0 Kudos
Reply