<Windows>Why does std::thread::native_handle return a value of type 'long long unsigned int' instead of void* (a.k.a. HANDLE)?

可紊 提交于 2021-02-05 09:44:37

问题


I need to suspend a thread on windows via Windows SDK on msys. I tried something like

std::thread thread(somefunction, someparameters);
HANDLE handle=thread.native_handle();
SuspendThread(handle);

But gcc told me the return value of native_handle() is 'long long unsigned int' but not void*. So I tried

HANDLE handle=reinterpret_cast<HANDLE>(thread.native_handle());

But it does not work because when I called GetLastError() I received the error code 6 which means the handle is invalid. What should I do?


回答1:


The returned "handle" is the thread id not the HANDLE as returned by CreateThread.

You need to use OpenThread to get a handle from the id.



来源:https://stackoverflow.com/questions/62751283/windowswhy-does-stdthreadnative-handle-return-a-value-of-type-long-long-u

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!