I have a data collection application running on Windows 7 using VC2010 in C ++. One thread is a heartbeat that sends changes every 0.2 seconds to support a certain amount of hardware, which has a wait time of about 0.9 seconds. Typically, a heartbeat call takes 10-20 ms, and the thread spends the rest of the sleep time.
Sometimes, however, there will be a delay of 1-2 seconds, and the hardware will temporarily shut down. The heartbeat thread runs on THREAD_PRIORITY_TIME_CRITICAL, which is 15 for the normal priority process. My other threads work with normal priority, although I use a DLL to manage some other equipment and noticed in Process Explorer that it starts several threads running at level 15.
I can’t track the source of the slowdown, but other add-ons in my application see the same delays when this happens. I have made several optimizations for the heartbeat code, although it is quite simple, but occasional crashes still occur. Now I wonder if I can increase the priority of this thread beyond 15 without specifying REALTIME_PRIORITY_CLASS for the whole process. If not, are there any flaws I should know about using REALTIME_PRIORITY_CLASS? (Apart from this heartbeat flow, the rest of the application does not have a real-time need.)
(Or does anyone have ideas on how to track these slowdowns ... not sure if the source could be in my application or somewhere else on the system).
: , 31 AfxBeginThread , 15, THREAD_PRIORITY_TIME_CRITICAL.
: - . REALTIME_PRIORITY_CLASS heartbeat THREAD_PRIORITY_TIME_CRITICAL ( 31), , . , , - AvSetMmThreadCharacteristics ( "Pro Audio" )
: , "Pro Audio" , 15 (Base = 1, Dynamic = 24), , , . , . , 5-10 - .