- Fix link resolution with proper relative/absolute path handling - Improve link styling with underline decoration - Hide leaf nodes from tree, only show directories - Fix log file path for packaged app
45 lines
1.1 KiB
Markdown
45 lines
1.1 KiB
Markdown
# TaskGroup::AddDependency
|
||
|
||
```cpp
|
||
void AddDependency(uint64_t taskId, uint64_t dependsOn)
|
||
```
|
||
|
||
为任务添加依赖关系。被依赖的任务必须先完成,当前任务才会开始执行。
|
||
|
||
**参数:**
|
||
- `taskId` - 任务 ID(需要等待的任务)
|
||
- `dependsOn` - 依赖的父任务 ID
|
||
|
||
**返回:** 无
|
||
|
||
**复杂度:** O(1)
|
||
|
||
**注意:**
|
||
- 如果被依赖的任务不存在或已完成,调用无效果。
|
||
- 支持添加多个依赖,但不支持循环依赖。
|
||
|
||
**示例:**
|
||
|
||
```cpp
|
||
TaskGroup* group = TaskSystem::Get().CreateTaskGroup();
|
||
|
||
uint64_t init = group->AddTask([]() { Initialize(); });
|
||
uint64_t task1 = group->AddTask([]() { Phase1(); });
|
||
uint64_t task2 = group->AddTask([]() { Phase2(); });
|
||
uint64_t cleanup = group->AddTask([]() { Cleanup(); });
|
||
|
||
// task1 和 task2 依赖 init
|
||
group->AddDependency(task1, init);
|
||
group->AddDependency(task2, init);
|
||
|
||
// cleanup 依赖 task1 和 task2
|
||
group->AddDependency(cleanup, task1);
|
||
group->AddDependency(cleanup, task2);
|
||
|
||
group->Wait();
|
||
```
|
||
|
||
## 相关文档
|
||
|
||
- [TaskGroup 总览](task-group.md) - 返回类总览
|