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.