简体   繁体   English

我想知道C ++中的延迟功能

[英]I want to know delay function in c++

usleep does not ensure delay exactly in userspace because of cpu situation. 由于cpu情况, usleep无法确保确切地延迟用户空间。

I want to know a function that ensures delay in userspace (c, c++) regardless of cpu situation. 我想知道一个确保无论cpu情况如何用户空间(c,c ++)的延迟的函数。

Unless you are using a hard real-time operating system (in which case, see its documentation), you are always vulnerable to the scheduler deciding to kick you out and let another thread run. 除非您使用硬实时操作系统(在这种情况下,请参阅其文档),否则调度程序决定将您踢出并让另一个线程运行总是容易受到攻击。 usleep makes this more likely (because the scheduler thinks "he didn't want to run for 100µs, what difference can another µs make?"), but there is no way to make it go away altogether. usleep使这种可能性更大(因为调度程序认为“他不想运行100µs,另一个µs会有什么不同?”),但是没有办法完全消除它。

It's not possible while you call such a function from the user space. 从用户空间调用这样的函数是不可能的。 Your processus can be preempted and forced to wait for a time before waking up again. 您的进程可能被抢占并被迫等待一段时间才能再次唤醒。 You should use a real-time sytem. 您应该使用实时系统。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM