Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a C++ equivalent of WaitforSingleObject?

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.

like image 254
Harry Boy Avatar asked Sep 26 '14 09:09

Harry Boy


1 Answers

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.

  • Wait for an object to be in a signaled state
  • Wait until a timeout elapses

Edit: specifically you would need wait_until

like image 175
Marco A. Avatar answered Sep 21 '22 05:09

Marco A.