We know that boost::this_thread::sleep_for(...)
can be used for putting the currently running thread into sleep. How different it is from the regular sleep()
function. It seems everyplace where we use boost::this_thread::sleep_for(...)
can be simply replaced by sleep()
method without affecting the results. Can anyone throw some light into it.
Asked
Active
Viewed 1,200 times
1

Vikas Umrao
- 2,800
- 1
- 15
- 23

Ramesh Chandra
- 13
- 4
-
`sleep()` isn't portable. – chris Apr 27 '15 at 03:39
2 Answers
3
C++ didn't provide a sleep function until C++11 came along, which offers std::thread::sleep_for(). So Boost provides its own for making your code platform-independent.
The C functions sleep(), usleep(), and Sleep() are platform-specific rather than part of the C++ standard library.

MrEricSir
- 8,044
- 4
- 30
- 35
0
sleep operates only at an one second level of granularity, as were boost::this_thread::sleep_for allows for sub 1 second granularity for the sleep.

diverscuba23
- 2,165
- 18
- 32