From 82cb73ae6b5afc8bf476c4800dd8b67a2f655233 Mon Sep 17 00:00:00 2001 From: ChunelFeng Date: Sat, 30 Nov 2024 22:51:44 +0800 Subject: [PATCH] [tutorial] update T07, update readme --- README.md | 2 +- tutorial/T07-MultiPipeline.cpp | 37 ++++++++++++---------------------- 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index da3b87e0..02477ccd 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ ## 一. 简介 -`CGraph`中文名为【色丶图】,是一套无任何第三方依赖的跨平台图流程执行框架。通过`GPipeline`(流水线)底层调度,提供了包含依赖元素依次执行、非依赖元素并发执行在 eDAG 调度功能。 +`CGraph`中文名为【色丶图】,是一套无任何第三方依赖的跨平台图流程执行框架。通过`GPipeline`(流水线)底层调度,提供了包含依赖元素依次执行、非依赖元素并发执行,支持暂停、恢复、超时设定的 `eDAG` 调度功能。 使用者只需继承`GNode`(节点)类,实现子类的`run()`方法,并根据需要设定依赖关系,即可实现任务的图化执行或流水线执行。还可以通过设定各种包含多节点信息的`GGroup`(组),自行控制图的条件判断、循环和并发执行逻辑。 diff --git a/tutorial/T07-MultiPipeline.cpp b/tutorial/T07-MultiPipeline.cpp index 403c4313..74017baa 100644 --- a/tutorial/T07-MultiPipeline.cpp +++ b/tutorial/T07-MultiPipeline.cpp @@ -11,41 +11,30 @@ using namespace CGraph; -void tutorial_pipeline_1(GPipelinePtr pipeline_1) { - if (nullptr == pipeline_1) { - return; - } - +std::future async_pipeline_1(GPipelinePtr pipeline_1) { GElementPtr node1A, node1B, node1C = nullptr; pipeline_1->registerGElement(&node1A, {}, "node1A"); pipeline_1->registerGElement(&node1B, {node1A}, "node1B"); pipeline_1->registerGElement(&node1C, {node1B}, "node1C"); - pipeline_1->process(5); // 执行n次,本例中 n=5 + // 异步执行 + return pipeline_1->asyncProcess(5); } -void tutorial_pipeline_2(GPipelinePtr pipeline_2) { - if (nullptr == pipeline_2) { - return; - } - +std::future async_pipeline_2(GPipelinePtr pipeline_2) { GElementPtr node2A, node2B, node2C = nullptr; pipeline_2->registerGElement(&node2A, {}, "node2A"); pipeline_2->registerGElement(&node2B, {node2A}, "node2B"); pipeline_2->registerGElement(&node2C, {node2A}, "node2C"); - pipeline_2->process(3); + return pipeline_2->asyncProcess(3); } -void tutorial_pipeline_3(GPipelinePtr pipeline_3) { - if (nullptr == pipeline_3) { - return; - } - +std::future async_pipeline_3(GPipelinePtr pipeline_3) { CStatus status; GElementPtr node3A, node3B, node3C, node3D = nullptr; GElementPtr region = nullptr; @@ -58,7 +47,7 @@ void tutorial_pipeline_3(GPipelinePtr pipeline_3) { region = pipeline_3->createGGroup({node3A, node3B, node3C, node3D}); pipeline_3->registerGElement(®ion); - pipeline_3->process(2); + return pipeline_3->asyncProcess(2); } @@ -89,13 +78,13 @@ void tutorial_multi_pipeline() { * 经过上述的设置,pipeline1 和 pipeline2 共享同一个线程池,去调度其中的dag逻辑 * pipeline3 没有设定,故使用自带的默认线程池完成自己的调度逻辑 */ - std::thread thd1 = std::thread(tutorial_pipeline_1, pipeline_1); - std::thread thd2 = std::thread(tutorial_pipeline_2, pipeline_2); - std::thread thd3 = std::thread(tutorial_pipeline_3, pipeline_3); + auto result1 = async_pipeline_1(pipeline_1); + auto result2 = async_pipeline_2(pipeline_2); + auto result3 = async_pipeline_3(pipeline_3); - thd1.join(); - thd2.join(); - thd3.join(); + result1.wait(); + result2.wait(); + result3.wait(); GPipelineFactory::clear(); }