是否有睡眠(c)中的方法吗? [英] Is there an alternative for sleep() in C?

查看:125
本文介绍了是否有睡眠(c)中的方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在传统的嵌入式编程,我们将给予延时功能,像这样:

In traditional embedded programming, we will give a delay function like so:

for(i=0;i<255;i++)
   for(j=0;j<255;j++);

在微处理器的看法,这是睡眠()函数是如何工作的?

In the microprocessor's view, is this how the sleep() function works?

有没有在C?

推荐答案

替代依赖于你正在尝试做的,什么操作系统你都在。

Alternatives depend in what you are trying to do and what OS you are on.

如果你只是想浪费时间,那么这些可能会帮助:

If you just want to waste time, then these might help:

在大多数Unix类型的系统,你会发现一个'usleep功能,这或多或少像更高分辨率的睡眠。小心那一个,因为它通常无法入睡仅为1微秒。

On most unix-type systems you'll find a 'usleep' function, which is more or less like sleep with greater resolution. Be careful with that one because it usually can not sleep for just one microsecond.

在某些UNIX类系统,选择系统调用可以与所有文件描述符集中使用,以获得一个相当准确的分一秒等待0。

On some unix-type systems, the select system call can be used with all file descriptor sets zero in order to get a fairly accurate sub-second wait.

在Windows系统中,你有睡眠,这是pretty大致相同,但采取的毫秒数。

On windows systems, you have Sleep, which is pretty much the same, but taking a number of milliseconds.

在一个多任务操作系统,睡眠功能有时可以作为一个参数给出0。这通常会导致函数放弃它的时间片,但如果没有其他的任务准备运行被立即重新安排。

In a multi-tasking operating system, a sleep function can sometimes be given 0 as a parameter. This generally causes the function to give up it's timeslice, but be re-scheduled immediately if no other task is ready to run.

这篇关于是否有睡眠(c)中的方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆