fix: improve doc link navigation and tree display
- 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
This commit is contained in:
40
docs/api/threading/thread/yield.md
Normal file
40
docs/api/threading/thread/yield.md
Normal file
@@ -0,0 +1,40 @@
|
||||
# Thread::Yield
|
||||
|
||||
```cpp
|
||||
static void Yield()
|
||||
```
|
||||
|
||||
让出当前线程的时间片,允许操作系统调度器将 CPU 时间分配给其他就绪线程。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**使用场景:**
|
||||
- 在自旋等待某个条件时调用,避免浪费 CPU 周期。
|
||||
- 在长时间循环中定期让出时间片,提高其他线程的响应性。
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
volatile bool ready = false;
|
||||
|
||||
Thread worker;
|
||||
worker.Start([]() {
|
||||
ready = true;
|
||||
}, "WorkerThread");
|
||||
|
||||
// 忙等待,但定期让出时间片
|
||||
while (!ready) {
|
||||
Thread::Yield();
|
||||
}
|
||||
|
||||
worker.Join();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Thread 总览](thread.md) - 返回类总览
|
||||
- [Sleep](sleep.md) - 线程休眠
|
||||
Reference in New Issue
Block a user