c++ - 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?
解决方案
一个简单的解决方法是让input_node
生成一个不使用shared_ptr
类型的消息,并立即提供给function_node
其输出使用shared_ptr
您想要传播的任何类型并在传播完成时收集的消息。感觉有点傻,但效果很好。除此之外可能还有节点input_node
进行缓存,但我正在使用function_node
, multifunction_node
,并且indexer_node
没有任何缓存的证据input_node
。
顺便说一句,当我在谷歌上搜索一个问题并最终在stackoverflow上解决我自己的一个问题时,它总是让我有点毛骨悚然,而且时间已经足够长,以至于我不记得发布过这个问题。当我没有看到答案时,也会给情绪增加一些失望。;-)
至少在我回来的时候,我已经足够习惯于 TBB 数据流,一个简单的解决方法是显而易见的。
推荐阅读
- parsing - Dart 语言是如何解析的(从左到右,接收等)?
- spring-security-oauth2 - OAuth2 身份验证 Web 服务调用后端客户端
- javascript - 使用静态类属性时 Node.js 的巨大性能问题
- ionic-framework - Ionic 4 页面导航
- google-cloud-platform - GCP和GSC的多个Google-site-verification元标记?
- c# - 如何将相关表添加到不相关表?
- google-apps-script - 注销后清除导航堆栈 - Gmail 插件
- sql - PostgreSQL: CAST() as money: 指定货币
- c++ - 检测到您的柯南配置文件设置和 CMake 之间的编译器版本不匹配
- python - 如何在 python 中打印完整的相关输出数组?另外,如果你能告诉我如何解释它们,那就太好了/