threading/: - Rename 19 camelCase method files to hyphenated names - task-system: createtaskgroup→create-task-group, etc. - tasksystemconfig: enabletaskprofiling→enable-task-profiling, etc. - thread: getcurrentid→get-current-id, etc. - task: addref→add-ref, getid→get-id, etc. math/: - Rename underscore operator files to hyphenated - vector3: operator_add→operator-add, etc. - matrix4: gettranslation→get-translation, etc. - vector4: tovector3→to-vector3, constructor_vector3→constructor-vector3 - sphere: sphere_constructor→sphere-constructor, etc. memory/: - Remove duplicate memorymanager/ folder (kept manager/ which was correct) core/: - filewriter: Consolidate ctor-default.md and ctor-file.md into constructor.md - Rename dtor.md→destructor.md debug/: - filelogsink: Rename construct.md→constructor.md, ~filelogsink.md→destructor.md All overview pages updated with new file references.
44 lines
1.1 KiB
Markdown
44 lines
1.1 KiB
Markdown
# Thread::GetCurrentId
|
|
|
|
```cpp
|
|
static Id GetCurrentId();
|
|
```
|
|
|
|
静态方法,返回当前执行线程的唯一标识符。此方法可在任意线程上下文中调用,包括主线程和工作线程。
|
|
|
|
线程 ID 通过 `std::this_thread::get_id()` 获取,并使用 `std::hash<std::thread::id>` 转换为 `uint64_t` 值。该值与 `Thread::GetId()` 返回的值格式一致,可以直接比较。
|
|
|
|
**参数:** 无
|
|
|
|
**返回:** 调用线程的唯一标识符
|
|
|
|
**线程安全:** ✅
|
|
|
|
**示例:**
|
|
|
|
```cpp
|
|
#include "XCEngine/Threading/Thread.h"
|
|
#include <iostream>
|
|
|
|
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;
|
|
}
|
|
```
|
|
|
|
## 相关文档
|
|
|
|
- [Thread 总览](thread.md) - 返回类总览
|
|
- [GetId](getid.md) - 获取 Thread 对象的 ID
|