使用 Qt 每个线程一个计时器
我修改了Qt的广播发送器示例,使其具有十个线程,并且在每个线程中启动一个计时器,但仅触发第一个线程的计时器。如何为每个线程运行一个计时器?
I modified Qt's broadcast sender example so that it has ten threads and in each thread it starts a timer, but only timer of the first thread is triggered. How can I have one timer running for each thread?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
计时器仅在线程具有事件循环时才起作用。
Timers only work if the thread has an event loop.
几年后,在操作系统课程中我学到了:
计时器是每个进程的东西。当操作系统内核发送计时器触发器时,即使当前正在运行的任何线程也会收到调用并处理它。
所以我不能以直接的方式为每个线程设置十个计时器。
A couple years later in OS course I learned:
Timers are a per process thing. When a the OS kernel sends a timer trigger even whatever thread that is currently running gets the call and processes it.
So I couldn't have ten timers per thread in a straight-forward manner.