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