Hello, and thank you all for TBB; it is a wonderful library. I am already using "parallel_do" to great effect in one application.
Now I am considering how to map a different application onto the TBB model, and flow graphs appear to be very close what I want.
However, my "messages" are large, so I need to limit how many of them are in flight at a time. I have read the "Flow Graph Tips for Limiting Resource Consumption" chapter -- in particular, the "Create a Token-Based System" section -- but the pull model it requires is very unnatural in my case.
The problem is that my message source really wants a push model. The actual generation of messages is deep inside a nested set of member function calls on various objects. Capturing all of that state in some kind of closure/continuation so that I can spit out the next message on-demand would require a major restructuring (and, in my opinion, uglification) of the code.
Is there a variant of try_put() that simply waits until there is room for the next message? Of course I do not want the underlying thread to block; I want it to go off processing other tasks like wait_for_all() etc.
Or is there some straightforward way to achieve a similar effect (e.g. a simple semaphore primitive that knows how to process other tasks while waiting)?