Impact of operating system on sleep (1)

Source: Internet
Author: User

Sometimes, to prevent 100% of CPU usage, sleep (1) is used to make the CPU take a short rest to achieve the smoothness of operating system task scheduling.

However, the effects of sleep (1) are different in different systems.

 

The original normal operation was found last week.ProgramIn the latest notebook, it cannot run normally, but it is always very slow. Later, it was traced and found that the reading speed of the file was too slow, it is found that it is caused by sleep (1) in the while () loop after the file is read.

 

After testing, we found that sleep (1) is equivalent to sleep (16) on the problematic notebook, and 15% of the probability is equivalent to sleep (15 ).CodeAs follows:

DWORD dw1 = gettickcount ();
Sleep (1 );
DWORD dw2 = gettickcount ();
Long Le = dw2-dw1;

It is found that most of the time Le is 16, and the probability of about 15% is 15.

The system of this notebook is Windows table pc xp + SP3 (the previous name is not clear, basically this version). The hardware configuration is very high: 3G memory, Intel t7700 CPU

 

Later, we tested sleep (1) on other systems, that is, the Le in the test code is always 0, and sleep (1) is required for every loop in the while () loop of File analysis ), so it is obvious that this sleep () takes too long to affect normal operation.

As a result, I do not know the impact of Operation on sleep (1) or the impact of hardware on sleep (1). I did not perform more detailed tests on each piece, but I came to the conclusion: this "small problem" cannot be taken lightly. It is very difficult to solve such problems if they only happen to customers.

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.