Sleep (100l) and wait (100l)

Source: Internet
Author: User
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.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.