Knowledge points:? Thread priority? Gets the current thread handle? Thread priority setting? Thread-priority change? Thread priority getting one, thread priority (thread priorities) is simply that the higher the priority, the more CPU time slices can be accounted for. Each process has a corresponding priority, and the priority determines when it runs and consumes CPU time. The final priority is divided into 32 levels, from0To tois called the base priority level. Process Precedence PriorityclassFlag Priority value IDLE (low) Idle_priority_class4Below below standard Below_normal_priority_class This value is below 2000 the system does not support normal (standard) Normal_priority_class9(front desk) or7(background) Above higher than standard above_normal_priority_class this value in 2000 the system does not support high (tall) High_priority_class -Realtime (real-time) Realtime_priority_class -when a thread is created, it inherits the priority level of the process. In addition, thread priority can be fine-tuned with setthreadpriority: fine-tuning range thread priority level flag priority value1Idle (minimum) Thread_priority_idle if the process priority is realtime, the adjustment is 16, and the other case is 12LOWEST Low Thread_priority_lowest-2(on the original basis-2)3BELOW below standard Thread_priority_below_normal-1(on the original basis-1)4Normal (standard) Thread_priority_normal invariant (take process priority value)5ABOVE above standard Thread_priority_above_normal +1(on the original basis +1)6Highest (h) Thread_priority_highest +2(on the original basis +2)7CRITICAL (highest) Thread_priority_time_critical if the process priority is realtime is adjusted to 31, the other case is 152, gets the current thread handle handle GetCurrentThread (VOID)//returns the current in handleDWORD GetCurrentThreadID (VOID)//returns the current process ID value 1, other thread functions bool SetThreadPriority Sets the priority level of a threadintGetThreadPriority Returns the priority level of a thread setthreadpriorityboost sets whether the thread disables the dynamic adjustment priority feature. Getthreadpriorityboost gets whether the thread has disabled the priority fine-tuning feature. Third, thread priority setting BOOL setthreadpriority (HANDLE hthread,//thread handle handle to the thread intNpriority//to set thread priority levels);voidCdialog_process::onbnclickedradio7 () {//TODO: Add control notification handler code hereBOOL r=0; UpdateData (true); Switch(m_radio_thread_selnum) { Case 0: R=setthreadpriority (GetCurrentThread (), thread_priority_idle);//set to lowestTRACE ("thread=%d,%04x set Priority to Thread_priority_idle \ n", GetCurrentThreadID (), GetCurrentThreadID ()); Break; Case 1: R=setthreadpriority (GetCurrentThread (), thread_priority_lowest);//set to LowTRACE ("thread=%d,%04x set Priority to Thread_priority_lowest \ n", GetCurrentThreadID (), GetCurrentThreadID ()); Break; Case 2: R=setthreadpriority (GetCurrentThread (), thread_priority_below_normal);//set to below standardTRACE ("thread=%d,%04x set Priority to Thread_priority_below_normal \ n", GetCurrentThreadID (), GetCurrentThreadID ()); Break; Case 3: R=setthreadpriority (GetCurrentThread (), thread_priority_normal);//Set as standardTRACE ("thread=%d,%04x set Priority to Thread_priority_normal \ n", GetCurrentThreadID (), GetCurrentThreadID ()); Break; Case 4: R=setthreadpriority (GetCurrentThread (), thread_priority_above_normal);//set to above standardTRACE ("thread=%d,%04x set Priority to Thread_priority_above_normal \ n", GetCurrentThreadID (), GetCurrentThreadID ()); Break; Case 5: R=setthreadpriority (GetCurrentThread (), thread_priority_highest);//set to HighTRACE ("thread=%d,%04x set Priority to Thread_priority_highest \ n", GetCurrentThreadID (), GetCurrentThreadID ()); Break; Case 6: R=setthreadpriority (GetCurrentThread (), thread_priority_time_critical);//set to highestTRACE ("thread=%d,%04x set Priority to thread_priority_time_critical \ n", GetCurrentThreadID (), GetCurrentThreadID ()); Break; default: Break; } }
Priority of MFC threads