简体   繁体   中英

I want to know delay function in c++

usleep does not ensure delay exactly in userspace because of cpu situation.

I want to know a function that ensures delay in userspace (c, c++) regardless of cpu situation.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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