Comments (5)
您好,感谢您的关注。
如果考虑使用全局变量的话,推荐通过添加切面的形式,实现上述逻辑。
参考 https://github.com/ChunelFeng/CGraph/blob/main/tutorial/T09-Aspect.cpp 这个demo,以获取更多的切面的好玩的用法
bool g_bRunning = true;
class MyStopAspect : public GAspect {
public:
CStatus beginRun() override {
CStatus status;
if (!g_bRunning) {
status.setStatus("stop"); // 遇到异常状况,设置异常返回信息
}
return status;
}
};
void demo() {
GPipelinePtr pipeline = GPipelineFactory::create();
GElementPtr a, b, c, d = nullptr;
CStatus status;
CStatus status = pipeline->registerGElement<MyNode1>(&a, {}, "nodeA");
status += pipeline->registerGElement<MyNode2>(&b, {a}, "nodeB");
status += pipeline->registerGElement<MyNode1>(&c, {a}, "nodeC");
status += pipeline->registerGElement<MyNode2>(&d, {b, c}, "nodeD");
pipeline->addGAspect<MyStopAspect>({a,b,c,d}); // 给每个算子,加上切面,确保在g_bRunning = false的时候,不继续执行
pipeline->process();
GPipelineFactory::remove(pipeline);
}
from cgraph.
这样以切面的方式停止,会不会造成资源泄漏啥的?
from cgraph.
您好。如果您的所有资源,是在 init的时候申请,destroy的时候释放,是不会造成内存泄漏的。
原因是,你加入这个 aspect的时候,实际运行逻辑,是在 bool被赋值后,执行的所有node的 run()方法 被执行前,直接就返回了。
不涉及任何资源分配,或者临时中断的内容
from cgraph.
就是说beginRun()会在node的init函数之前执行?
from cgraph.
在beginRun(), node的 run之前,见名知意。
同时,还是 beforeInit() 切面,在 init()之前。
pipeline中,所有node的 init方法和 destroy方法,均只执行一次。
run方法,可以反复多次执行。
from cgraph.
Related Issues (20)
- 抽象出来 state manager 的逻辑
- 【feat】support the compiling way of bazel HOT 2
- 关于CGRAPH_RECV_MPARAM_WITH_TIMEOUT的使用 HOT 2
- GPipelineFactory::remove(pipeline)执行时,报了free(): invalid pointer
- CGraph可以分析C项目,将其拆分成DAG图吗? HOT 1
- GMultiCondition的奇怪用法 HOT 2
- taskflow 对比测例 HOT 1
- 修改内容,待发版
- registerGElement 构造传参 HOT 3
- 修改一下备注信息
- mutable 的 带依赖的并发逻辑是否存在bug HOT 1
- 考虑使用 std::shared_future<int> 来处理 异步event信息 HOT 2
- 使用 bfs 实现一个版本的的静态引擎 HOT 1
- 线程池的优化思路
- 修改掉
- 需要添加一个 small vector的逻辑 HOT 1
- 提供 不获取 future 返回值的commit 版本,对比性能 HOT 1
- 执行过程中,会有线性拖累的问题 HOT 2
- 解析图中的树形结构,加速run 的执行
- 异步执行时,立刻执行yield可能失效。 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cgraph.