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)
- 看这里是否可以通过 减少notify 的方式,来增加并行速度 HOT 2
- 如果 element 后面的是 empty,这里都是不需要的 HOT 1
- Hope adding vcpkg package for cgraph HOT 5
- ninja 的构建方式,需要chmod一下
- 介绍一下 eDAG的思路
- 这里记得 final 一下
- 单独模块执行
- topo sort 之后,单线程执行
- 这里设置的位置,要靠后一些
- 这里应该是 +=,不是 =
- 提供一些好用的 debug功能
- 提供一些批量执行的方式 HOT 1
- 编译源码静态库或者动态库 HOT 1
- 提供一个 map-reduce的 example 吧
- 这里是要改掉的
- mutable 中,提供 设置 engine类型的函数
- 可以考虑加入以下内容,来区分 release or debug 版本 HOT 1
- 如何从主线程里面拿到异步线程的执行结果? HOT 2
- 修改一下 返回值的标识
- localtime和unlikely处的warning HOT 3
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.