Skip to content
JeffGarland edited this page May 14, 2013 · 1 revision

Problem

You need to sleep for less than a second.

Solution

The C++11 chrono library provides a direct solution to this problem in the thread library. The library offers a number of different time resolutions.

 using std::chrono::milliseconds;
 std::this_thread::sleep_for(milliseconds(10));

Discussion

Here's some examples of using other duration types

 using std::chrono::seconds;
 using std::chrono::microseconds;
 std::this_thread::sleep_for(microseconds(2000));
 std::this_thread::sleep_for(seconds(1));
Clone this wiki locally