在我的一个项目中,我需要高效地安排要反复执行的不同操作,每个操作都有自己的时间间隔。
我一直在想,当我使用 SetTimer函数,后台发生了什么?
是否创建了新线程? 它是否在后台运行并占用我的 CPU?还是它会一直睡到操作系统在适当的时候唤醒它? 有大量计时器是否可以,或者是否有充分的理由尝试尽量减少它们的数量?
谢谢。
最佳答案
Is a new thread created?
没有。
Does it run in the background and eats my CPU?
不 - 试一试。设置计时器并检查任务管理器。
does it sleep until the OS awakens it when the time comes?
是的。
Is it OK to have a large amount of timers or is there a good reason to try and minimize their amount?
对于今天的系统来说,很多计时器并不是一个巨大的开销,但你应该仔细考虑这样的要求..
关于c++ - SetTimer 函数是在后台运行还是进入休眠状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34337104/