I'm new to the Intel Threading Building Blocks and playing with the flow graph component. So far, its worked mostly well. My messages between nodes are shared_ptr
types so they are copy-constructble, lightweight, and the underlying resource is disposed of at the end of a graph cycle...
Except for messages that originate from my input_node
. input_node
is designed so that it holds a copy of its last output value. This means that the any resource held by the value output by an input_node
won't be released until the input_node
generates its next output.
This seems awkward/inconsistent with the rest of the API. Any thoughts on how to deal with it? I guess I could write my own node, but I'd rather not. Should I just use try_put
? If so, how do I let the graph know when I'm done providing inputs, so that wait_for_all
doesn't conclude early?
An easy workaround is to have the
input_node
generate a message which does not utilizeshared_ptr
types, and feeds immediately to afunction_node
whose output does utilize anyshared_ptr
types you want to propagate and have collected when the propagation is complete. It feels a little silly, but works well. There may be nodes besidesinput_node
that do caching, but I'm usingfunction_node
,multifunction_node
, andindexer_node
without any evidence of the caching thatinput_node
does.As an aside, it always creeps me out a little bit when I google a problem and end up on one of my own questions on stackoverflow, and it's been long enough that I don't remember posting the question. When I don't see an answer it adds some disappointment to the emotions too. ;-)
At least on this one by the time I came back I had become used enough to TBB dataflow that an easy workaround was readily apparent.