Files
XCEngine/docs/api/XCEngine/Threading/TaskSystem/Shutdown.md

46 lines
1.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# TaskSystem::Shutdown
关闭任务系统并回收工作线程。
```cpp
void Shutdown();
```
## 行为说明
当前实现会:
1.`m_running` 设为 `false`
2.`m_shutdown` 设为 `true`
3. `notify_all()` 唤醒等待任务的工作线程。
4. 逐个 `join()` 仍然可连接的工作线程。
5. 清空 `m_workerThreads`
## 返回值
- 无。
## 当前实现限制
- 当前不会清空 `m_taskQueue`,未执行的任务会被直接遗留。
- 当前不会释放队列中残留任务对应的对象。
- 当前不会销毁已经通过 [CreateTaskGroup](CreateTaskGroup.md) 创建的任务组。
- 当前不会清空 `m_mainThreadQueue`
- `m_shutdown` 会一直保持为 `true`,这使得重新初始化路径当前不可用。
## 设计说明
商业级任务系统的关闭通常需要定义明确的 shutdown policy例如
- 等待现有任务自然跑完。
- 取消可取消任务并清理资源。
- 强制丢弃队列但保证对象生命周期可回收。
当前实现只覆盖了“停线程”这一步。
## 相关文档
- [返回类型总览](TaskSystem.md)
- [Initialize](Initialize.md)
- [Submit](Submit.md)