docs: rebuild Threading API content
This commit is contained in:
36
docs/api/XCEngine/Threading/SpinLock/Lock.md
Normal file
36
docs/api/XCEngine/Threading/SpinLock/Lock.md
Normal file
@@ -0,0 +1,36 @@
|
||||
# SpinLock::Lock
|
||||
|
||||
自旋直到获得锁。
|
||||
|
||||
```cpp
|
||||
void Lock();
|
||||
void lock();
|
||||
```
|
||||
|
||||
## 行为说明
|
||||
|
||||
当前实现有两套入口:
|
||||
|
||||
- `Lock()`:引擎风格命名。
|
||||
- `lock()`:标准 Lockable 风格别名。
|
||||
|
||||
核心逻辑是一个空循环:
|
||||
|
||||
```cpp
|
||||
while (m_flag.test_and_set(std::memory_order_acquire)) {
|
||||
}
|
||||
```
|
||||
|
||||
## 返回值
|
||||
|
||||
- 无。
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 持锁时间稍长时会持续占用 CPU。
|
||||
- 适合极短临界区,不适合可能阻塞的工作。
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [返回类型总览](SpinLock.md)
|
||||
- [Unlock](Unlock.md)
|
||||
Reference in New Issue
Block a user