Ideas on asynchronous infinite loop

Ideas on asynchronous infinite loop

Hello,

I have an idea that I'd like to implement, but I don't know where to start.

The class I intend to write is a disk intensive task one, so I'd like to have its users submit data to be written to disk, and return immediately before the actual disk operation. I believe this could be done with this:

  • concurrent_queue will be used to submit data to be written, the function will enqueue and exit immediately
  • parallel_do or similar construct that monitors the queue and does the hard work
  • the infinite loop should, I believe, run a separate thread

I don't think what I've written corresponds to the best implementation, or it suits TBB the best.

Do you have any suggestions?

Thank you!
    Franco

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

Hi Franco!

Your idea is similar that we have in fgbzip2 example. This Flow Graph example uses async_node to read/write file asynchronously.

Thanks,

Nikita

Thanks, Nikita. I find it really cool, but probably more complicated than needed. 

Is there an easier way of achieving this? 

Thank you!

I suppose that concurrent queue with infinite thread is the easiest way to achieve what you want.

You could also try this approach, but it is a little bit more complex.

Nikita

Leave a Comment

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