C++: How to sleep for a nanosecond? [duplicate] C++: How to sleep for a nanosecond? [duplicate] windows windows

C++: How to sleep for a nanosecond? [duplicate]


Using C++11

#include <chrono>#include <thread>...std::this_thread::sleep_for(std::chrono::nanoseconds(1));

Note that the implementation may sleep longer than the given period.


You should also notice that there is the scheduler, which probably allows no sleeps that are shorter than an timeslice (somewhat around 4 ms - 10 ms, depending on your windows and machine). sleeping less than that is not possible on

Here are some (quite old) research on that issue windows.

This article suggests using Win32 timeBeginPeriod() to achieve that.