Windows Programming-thread sleep

Source: Internet
Author: User
Tags sleep function


The thread can also tell the system that it does not want to be scheduled within a certain period of time. This is achieved by calling the Sleep function:

VOIDSleep(DWORDdwMilliseconds );

This function can pause the thread until dwMilliseconds has passed. About Sleep functions.

 

There are several important issues worth noting:

1. Call Sleep to make the thread voluntarily give up its remaining time slice.

2. The system will make the thread unschedulable within a specified millisecond. If you tell the system that you want to sleep for 100 ms, you can sleep for about this long time, but you may also sleep for several seconds or several minutes. Remember, Windows is not a real-time operating system. Although a thread may be awakened at a specified time, whether it can be done depends on what operations are in progress in the system.

3. Sleep can be called and passed as the dwMilliseconds parameter.INFINITE. This tells the system never to schedule this thread. This is not something worth doing. It is best to let the thread exit and restore its stack and kernel objects.

4. You can set0Passed to Sleep. The call thread will release the remaining time slices and force the system to schedule another thread. However, the system can reschedule the thread that just called Sleep. This problem occurs if there are no scheduling threads with the same priority.

 

FangSH 2010-12-28

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.