Rahul Das
Rahul Das

Reputation: 124

std::this_thread::sleep_for() vs sleep() in main()

std::this_thread::sleep_for() Or usleep()

What would be better to be used in main()? This may be very silly but i am new to C++11 features.

Upvotes: 2

Views: 1099

Answers (1)

ShadowRanger
ShadowRanger

Reputation: 155363

The former is actually a portable C++ function. The latter is an obsolete, non-portable POSIX function (replaced by nanosleep, which remains non-portable). Use std::this_thread::sleep_for(), which will likely be implemented in terms of nanosleep when available/appropriate, or whatever other function the system provides otherwise.

Upvotes: 6

Related Questions