I wanted to know what is the difference between C++11 std::this_thread::yield()
and std::this_thread::sleep_for()
? And how to decide what to use? T
std::this_thread::sleep_for()
will make your thread sleep for a given time (the thread is stopped for a given time). (http://en.cppreference.com/w/cpp/thread/sleep_for)
std::this_thread::yield()
will stop the execution of the current thread and give priority to other process/threads (if there are other process/threads waiting in the queue). The execution of the thread is not stopped. (it just release the CPU). (http://en.cppreference.com/w/cpp/thread/yield)