C、2个事件及时序问题
我会分叉3个线程, 一个用于事件 A,另一个用于事件 B,第三个用于计时。
我将每 3.2 秒运行一次 A,每 1.7 秒运行一次 B。
我的想法是在线程3中,在适当的时候,我调用A或B。
这个逻辑对吗? 线程3中A和B的调用会影响时序吗?
谢谢
I will fork 3 threads,
One for event A, another for event B, third one for timing.
I will run A in every 3.2 sec, run B in every 1.7 sec.
My thought is in thread 3, at proper time, I call A or B.
Is this logic right?
Will the calling of A and B in thread 3 influence timing ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,执行一个线程会影响其他线程的执行时间和持续时间。任何其他正在运行的进程以及任务调度程序和线程库的设计也会如此,更不用说操作系统的当前状态,它可能决定将进程/线程的执行延迟任意时间。
如果你想确保你的线程在一定的时间间隔内执行某些操作,你必须使用一个可以保证其进程执行的操作系统,或者你必须想出一个巧妙的设计来处理这种情况在一段时间间隔内,线程 A 或 B 尚未完成(或完成)其任务。
Yes, executing one thread will influence the execution time and duration of the other threads. So will any other running processes as well as the design of your task scheduler and your thread library, not to mention the current mood of your operating system, which may decide to delay the execution of your processes/threads by an arbitrary amount of time.
If you want to make sure that your threads perform some action in certain time intervals, you have to either use an operating system which can make guarantees towards the execution of its processes, or you have to come up with a clever design which handles the case where a time interval passed without thread A or B having done (or completed) its task.