Knowledge points:
1. Use suspendthread and resumethread to pause and resume thread running.
2. Through the sleep function, the thread can tell the system that it does not want to be scheduled within a certain period of time. The system will make the thread unschedulable within a specified millisecond. If 0 is passed to the sleep function, the call thread will release the remaining time slice and force the system to schedule another thread.
3. The system provides a function called switchtothread to run another schedulable thread (if any.
4. When calculating how long it takes for a thread to execute a task, if gettickcount is used, it is assumed that the current thread will not be interrupted. Therefore, we need a function to return the number of CPU times obtained by the current thread. The getthreadtimes function can do this. Getprocesstimes is a function corresponding to a process and is applicable to all threads in the process.
5. Windows also provides some high-resolution performance functions: queryperformancefrequency and queryperformancecounter.
6. Windows allows getthreadcontext and setthreadcontext to get and set the thread context. However, you should suspend the thread before obtaining and setting it.
7. When the system boots, it creates a special thread, called a 0-page thread. This thread is given a priority of 0. It is the only thread running on priority 0 in the system. When no threads in the system need to perform operations, the 0-page thread is responsible for setting all idle Ram pages in the system to 0.
8. The process can use setpriorityclass and getpriorityclass to set and query priority classes. The thread can use setthreadpriority and getthreadpriority to set and query the thread priority.
9. The system can set the basic priority level in the dynamic priority range (1 ~ 15) threads within the thread dynamically increase the priority level of the thread (for example, when a low-priority thread is in the CPU hunger State or when a process is a foreground process ), however, the system will never raise the priority to the real-time range (higher than 15 ).
10. You can use setprocesspriorityboost and setthreadpriorityboost to disable the function of dynamically increasing the thread priority level. The getprocessprorityboost and getthreadpriorityboost functions are used for query.
11. Use setprocessaffinitymask and getprocessaffinitymask to set and obtain the affinity of processes. Use setthreadaffinitymask to set affinity blocking for each thread. To set an ideal CPU for a thread, call setthreadidleprocessor.