Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does SetPriorityClass(REALTIME_PRIORITY_CLASS) actually do?

What does REALTIME_PRIORITY_CLASS (with THREAD_PRIORITY_TIME_CRITICAL) actually do?

Does it:

  • Prevent interrupts from firing
  • Prevent context switching from happening

on the processor (unless the thread sleeps)?

If it does prevents the above from happening:

  • How come when I run a program on a processor with this flag, I still get inconsistent timing results? Shouldn't the program take the same amount of time every time, if there's nothing interrupting it?

If it does NOT prevent the above from happening:

  • Why does my system (mouse, keyboard, etc.) lock up if I use it incorrectly? Shouldn't drivers still get some processor time?
like image 370
user541686 Avatar asked Jan 30 '26 13:01

user541686


1 Answers

It basically tells the system scheduler to only a lot time to your thread till it gives it up(via Sleep or SwitchToThread) or dies. As for timing not being the same, the OS still runs inbetween each run, this can change ram and caching etc. Secondly, most timing is inaccurate, so it will fluctuate(especially system quanta based timing like GetTickCount). The OS many also have thing things going on, like power saving/dynamic freq adjustment, so you best check would be to use RDTSC, though even with that you might notice other stuff running(especially if you can run more than one physical thread).

like image 167
Necrolis Avatar answered Feb 01 '26 21:02

Necrolis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!