docs: update memory and threading API docs
This commit is contained in:
@@ -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;
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
Reference in New Issue
Block a user