Reputation: 4747
I need to rewrite some code that uses the windows WaitforSingleObject function.
myEvent = CreateEvent( NULL, FALSE, FALSE, szName );
WaitForSingleObject( myEvent, nMilliseconds );
I need to wait for an event or for a timeout to happen. Is there an equivalent to this in straight C++??
I am using STL C++11 and not any other libraries such as boost.
Upvotes: 10
Views: 13096
Reputation: 1736
Yes, you can use C++11 Only. Here is an example (too long to be pasted here): https://github.com/moya-lang/Event/blob/master/Event.h. The code fully mimics WINAPI Event Objects so this is something you are asking for.
Upvotes: 0
Reputation: 43662
You can't use C++11 thread routines with win32 threads (unless you heavily mess up with mingw thread implementations, something I would not recommend) and there's no standard C++ equivalent to an OS-specific API call.
You can, however use C++11 threads and use condition variables (cfr. waiting) to accomplish the same thing that WaitForSingleObject does, i.e.
Edit: specifically you would need wait_until
Upvotes: 6