Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CPP WINDOWS : is there a sleep function in microseconds?

Tags:

c++

sleep

windows

I know there is for milliseconds (Sleep(milli))

but I couldn't find one for micro..

like image 467
kakush Avatar asked Feb 02 '12 17:02

kakush


1 Answers

The VS 11 dev preview includes the part of the standard library dealing with threads. So now you can say:

std::this_thread::sleep_for(std::chrono::microseconds(1));

Of course this doesn't mean the thread will wake up after exactly this amount of time, but it should be as close as the platform (and library implementation) allows for. As other comments have pointed out, Windows doesn't actually allow threads to sleep for durations this short.

like image 141
bames53 Avatar answered Sep 17 '22 11:09

bames53