首页 > 解决方案 > Intel TBB input_node output value caching delays resource release. Workaround ideas?

问题描述

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?

标签: c++shared-ptrtbbreference-countingtbb-flow-graph

解决方案


一个简单的解决方法是让input_node生成一个不使用shared_ptr类型的消息,并立即提供给function_node其输出使用shared_ptr您想要传播的任何类型并在传播完成时收集的消息。感觉有点傻,但效果很好。除此之外可能还有节点input_node进行缓存,但我正在使用function_node, multifunction_node,并且indexer_node没有任何缓存的证据input_node

顺便说一句,当我在谷歌上搜索一个问题并最终在stackoverflow上解决我自己的一个问题时,它总是让我有点毛骨悚然,而且时间已经足够长,以至于我不记得发布过这个问题。当我没有看到答案时,也会给情绪增加一些失望。;-)

至少在我回来的时候,我已经足够习惯于 TBB 数据流,一个简单的解决方法是显而易见的。


推荐阅读