docs: update memory and threading API docs

This commit is contained in:
2026-03-20 02:35:24 +08:00
parent c5b17239ca
commit fd792b7df1
103 changed files with 2485 additions and 673 deletions

View File

@@ -1,27 +1,41 @@
# Thread::GetId
```cpp
Id GetId() const
Id GetId() const;
```
获取当前线程对象的唯一标识符。 ID 在线程启动后有效
返回当前线程对象的唯一标识符。线程 ID `uint64_t` 类型的值,通过 `std::thread::native_handle()` 获取原生线程句柄并转换为整数
线程 ID 在线程启动后生效。在调用 `Start()` 之前,`GetId()` 返回 0。
**参数:**
**返回:** `Thread::Id` - 线程的唯一标识符uint64_t 类型)
**返回:** 线程的唯一标识符,线程未启动时返回 0
**复杂度** O(1)
**注意:** 在调用 Start 之前返回 0。
**线程安全**
**示例:**
```cpp
Thread worker;
printf("Before start: id=%llu\n", (unsigned long long)worker.GetId());
worker.Start([]() {}, "Test");
printf("After start: id=%llu\n", (unsigned long long)worker.GetId());
worker.Join();
#include "XCEngine/Threading/Thread.h"
#include <iostream>
using namespace XCEngine::Threading;
int main() {
Thread t;
std::cout << "Before Start - Thread ID: " << t.GetId() << std::endl;
t.Start([]() {
std::cout << "Worker ID: " << Thread::GetCurrentId() << std::endl;
}, "WorkerThread");
std::cout << "After Start - Thread ID: " << t.GetId() << std::endl;
t.Join();
return 0;
}
```
## 相关文档