Yes. std::this_thread::sleep_for is defined by the C ++ 11 standard and, therefore, is a portable solution on any system with a C ++ 11 compiler and a standard library.
usleep is specified by POSIX.1-2001 (and is deprecated!), which means that it can (reliably) be used only on POSIX-compatible systems.
POSIX.1-2008 removes the usleep specification, in favor of nanosleep . For this reason, std::this_thread::sleep_for is a much better choice.
(For more details see http://linux.die.net/man/3/usleep .
source share