Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Native Thread Handle from C++11 Thread for Win32 API [duplicate]

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?

like image 579
Soha Avatar asked Jun 05 '26 23:06

Soha


1 Answers

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.

like image 180
Some programmer dude Avatar answered Jun 08 '26 12:06

Some programmer dude



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!