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

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 !


4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

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.

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

thank you Alexey Kukanov and Jim Dempsey

Leave a Comment

Please sign in to add a comment. Not a member? Join today