Reputation: 8704
I'm developing a console C++ application with Visual Studio on Windows XP that must be at the highest priority possible for the scheduler.
int main()
{
while ( somecondition )
{
// pick data from external hardware every 10 milliseconds
// do computation
}
}
I mean no other system process should interfere with it because it's a real time data acquisition system tuned to refresh the frame buffer every 10 milliseconds.
I tried to save to a file the temporal length of each frame and I found a strange "quantization" around my desidered time. Why?
I also found that sometimes the length is a multiple of my base frame time, is this caused by interfering internal O.S. processes?
Is there a way to ensure the highest priority of my program?
Upvotes: 0
Views: 2355
Reputation: 14638
All you need is to call SetThreadPriority
I used like this:
HANDLE hThread = GetCurrentThread(void);
SetThreadPriority(hThread, THREAD_PRIORITY_TIME_CRITICAL);
Just to to note that other application can do same, so both threads will have same priority.
Upvotes: 2