Files
XCEngine/docs/api/threading/task-group/wait.md
ssdfasd 7dd7858ef2 docs: fix threading module documentation discrepancies
- Fix SpinLock docs: clarify lock()/unlock()/try_lock() are non-const
  (matching source implementation in SpinLock.h)
- Add missing LambdaTask::Execute() method to inherited methods table
- Update TaskGroup::Wait() docs: clarify m_pendingCount never decrements
  causing indefinite block even after all tasks complete (not just
  unexecuted tasks)
- Update TaskGroup::IsComplete() docs: document same m_pendingCount
  issue causing incorrect return values
2026-03-19 01:03:14 +08:00

42 lines
953 B
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.
# TaskGroup::Wait
```cpp
void Wait()
```
阻塞当前线程,等待任务组中所有任务完成。
**参数:**
**返回:**
**复杂度:** O(n)n 为任务数量
**注意:**
- 如果任务组已被取消,此方法将立即返回。
- **警告**:由于实现缺陷,`m_pendingCount` 计数器在任务完成后不会递减,导致 `Wait()` 在所有任务执行完毕后仍会永久阻塞。这是当前实现的已知问题。
- 建议使用 `WaitFor()` 代替以避免永久阻塞。
**示例:**
```cpp
TaskGroup* group = TaskSystem::Get().CreateTaskGroup();
for (int i = 0; i < 10; ++i) {
group->AddTask([i]() {
printf("Task %d running\n", i);
});
}
printf("Waiting for all tasks...\n");
group->Wait();
printf("All tasks completed!\n");
TaskSystem::Get().DestroyTaskGroup(group);
```
## 相关文档
- [TaskGroup 总览](task-group.md) - 返回类总览
- [WaitFor](waitfor.md) - 超时等待