Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Marc_R_5
Beginner
97 Views

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

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_K_Intel3
Employee
97 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.

jimdempseyatthecove
Black Belt
97 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

Adel_S_
Beginner
97 Views

thank you Alexey Kukanov and Jim Dempsey

Reply