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,40 @@
# Thread::GetCurrentId
```cpp
static Id GetCurrentId()
static Id GetCurrentId();
```
获取当前执行线程的唯一标识符。这是一个静态方法,可以在任线程上下文中调用。
静态方法,返回当前执行线程的唯一标识符。此方法可在任线程上下文中调用,包括主线程和工作线程
线程 ID 通过 `std::this_thread::get_id()` 获取,并使用 `std::hash<std::thread::id>` 转换为 `uint64_t` 值。该值与 `Thread::GetId()` 返回的值格式一致,可以直接比较。
**参数:**
**返回:** `Thread::Id` - 当前执行线程的唯一标识符
**返回:** 调用线程的唯一标识符
**复杂度** O(1)
**线程安全**
**示例:**
```cpp
Thread worker;
worker.Start([]() {
printf("Worker thread id: %llu\n", (unsigned long long)Thread::GetCurrentId());
}, "WorkerThread");
#include "XCEngine/Threading/Thread.h"
#include <iostream>
printf("Main thread id: %llu\n", (unsigned long long)Thread::GetCurrentId());
worker.Join();
using namespace XCEngine::Threading;
int main() {
std::cout << "Main thread ID: " << Thread::GetCurrentId() << std::endl;
Thread t;
t.Start([]() {
std::cout << "Worker thread ID: " << Thread::GetCurrentId() << std::endl;
std::cout << "Worker ID matches Thread.GetId(): "
<< (Thread::GetCurrentId() == t.GetId() ? "Yes" : "No") << std::endl;
}, "CheckIdThread");
t.Join();
return 0;
}
```
## 相关文档