SetPriorityClass(REALTIME_PRIORITY_CLASS) 实际上做了什么?
REALTIME_PRIORITY_CLASS
(使用 THREAD_PRIORITY_TIME_CRITICAL
)实际上吗?
是否:
- 防止中断触发
- 防止处理器上发生上下文切换
(除非线程休眠)?
如果它确实阻止了发生上述情况:
- 为什么当我在带有此标志的处理器上运行程序时,我仍然得到不一致的计时结果?如果没有任何事情打断的话,程序不是应该每次都花费相同的时间吗?
如果它不能阻止发生上述情况:
- 如果我使用不当,为什么我的系统(鼠标、键盘等)会锁定?驱动程序不应该仍然获得一些处理器时间吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它基本上告诉系统调度程序只给你的线程很多时间,直到它放弃它(通过
Sleep
或SwitchToThread
)或死亡。至于计时不一样,操作系统在每次运行之间仍然运行,这可能会改变内存和缓存等。其次,大多数计时都是不准确的,所以它会波动(特别是基于系统量子的计时,如GetTickCount
)。许多操作系统也有一些事情正在发生,比如省电/动态频率调整,所以你最好检查是使用 RDTSC,尽管即使这样你可能会注意到其他东西正在运行(特别是如果你可以运行多个物理线程) 。It basically tells the system scheduler to only a lot time to your thread till it gives it up(via
Sleep
orSwitchToThread
) 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 likeGetTickCount
). 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).