The meaning of Sleep (0) is to discard the current thread execution time slices and put itself in the waiting queue. At this point the other threads will get the time slice to program the program. Sleep (0) can reduce the execution speed of the current thread, such as: Now there are 100 threads in the system (assuming a thread bar) to perform different tasks, and they perform the same priority, and each time the slice is allocated the same length. Now that there is a sleep (0) in the current thread, the wait time for the current thread to get the time slice is extended by 1 time times, which means that it is equivalent to 200 time slices before the time slice is executed.
The function is not in the standard library
But in some compiled systems, there are some system libraries, depending on your environment.
Such as:
Linux, unsigned int sleep (unsigned intseconds), incoming suspend time, successfully returned 0, unsuccessful returns the remaining number of seconds.
The Windows system has the Sleep function (note uppercase), void Sleep (DWORD dwmilliseconds), and provides the number of milliseconds to suspend.
Sleep is to hang yourself up and end the current time slice
For example:
#include <iostream>
#include <windows.h>
using namespace Std;
int main ()
{
Sleep (3000);//pause for 3 seconds s to capitalize
return 0;
}
Use std::this_thread::sleep_for
:
:::: (111605 //or Whatever:::: ();
There is also the complimentary std::this_thread::sleep_until
.
Prior to C++11, C + + had no thread concept and no sleep capability, so your solution was necessarily platform dependent. Here's a snippet that defines a sleep
function for Windows or Unix:
#ifdef#include<windows.h>void(Unsigned){SleepMilliseconds}#else#include<unistd.h>void(Unsigned){ (*1000} #endif
But a much simpler pre-C++11 method is to use boost::this_thread::sleep
C + + Sleep (0)