Sleep is used to sleep when a thread is called and the CPU is occupied. Other threads cannot occupy the CPU. The OS considers the thread to be working and will not let out system resources,
Wait enters the wait pool to wait, giving way to system resources. Other threads can occupy the CPU. Generally, wait does not apply time restrictions,
It is useless if the wait thread does not run enough resources,
Wait for other threads to call the yyall method to wake up all the threads in the wait pool before entering the ready sequence to wait for the OS to allocate system resources. Sleep is a static method, who calls and who goes to bed, even if the sleep method of thread B is called in the main thread, the main thread actually goes to bed,
To let thread B go to bedCodeSleepsleep (100 L) is used for CPU usage, the thread sleep for milliseconds, other processes can no longer use CPU resources, and wait (l) is used for waiting in the waiting pool,
Hand over CPU and other system resources for other processes,
In this 100 ms, the thread can be y by other threads, but the difference is that other threads in the waiting pool will not be y,
However, this thread will automatically enter the ready queue after waiting for 100 milliseconds to wait for the system to allocate resources,
In other words, sleep (100) will certainly run after 100 milliseconds, but wait will wait for the OS to call and allocate resources after 100 milliseconds,
Therefore, the wait100 stop time is uncertain, but at least 100 milliseconds.
In addition, we will add the following knowledge about wait () functions:
_ Cribd void _ cdecl wait (
Unsigned int _ milliseconds
);
_ Cribd void _ cdecl wait (
Unsigned int _ milliseconds
);
Parameter _ milliseconds
The number of milliseconds that the current context should be paused.If the _ milliseconds parameter is set to 0, it indicates that the current context should execute other runable contexts before continuing.