I started to use C++11 std::thread
(mingw 4.8) so far so good. I ran into a situation with overlapped I/O where sleepEx
was used to put the thread in an alertable wait state. This worked quite well, until QueueUserAPC
had to be used, which returned an "invalid handle error".
After some searching found out that std::thread
uses the pthread library under Windows.
Is there any way to use windows API calls which expect a thread handle with std::thread
?
Or do I need to stick with Windows threads for overlapped I/O ?
Is there any way to use windows API calls which expect a thread handle with std::thread ?
No, because the Edit: it is, but indirectly, see rubenvb's answer for how to get the native thread handle from a std::thread
in your MinGW build isn't implemented in terms of thread handles.pthread_t
, and you should be able to use std::thread::native_handle()
to get the pthread_t
.
Noone has implemented the necessary support in GCC for the C++11 thread library to use native Windows threads directly.
I had some ideas for a new thead model that would be implemented in terms of native mutexes and condition variables. That would allow you to call std::thread::native_handle()
to get the underlying thread handle to use with the Windows API.
I got as far as rebuilding GCC with my changes applied, but couldn't test them. There was almost no interest in my suggestions and no offers to help from any MinGW contributors, so as I'm not a Windows user, and working on Windows and building MinGW was so painful and frustrating, I gave up. I should put my changes online somewhere, so that someone with more patience than me can finish the work one day.