Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4182673
  • 博文数量: 776
  • 博客积分: 13014
  • 博客等级: 上将
  • 技术积分: 10391
  • 用 户 组: 普通用户
  • 注册时间: 2010-02-22 17:00
文章分类

全部博文(776)

文章存档

2015年(55)

2014年(43)

2013年(147)

2012年(20)

2011年(82)

2010年(429)

分类: LINUX

2011-04-22 09:32:56

用户空间:

1.unsigned int sleep(unsigned int seconds); 
  sleep()会使当前程序休眠seconds秒。如果sleep()没睡饱,它将会返回还需要补眠的时间,否则一般返回零。 
 
2.void usleep(unsigned long usec); 
 usleep与sleep()类同,不同之处在于休眠的时间单位为毫秒(10E-6秒)。 
 
3.int select(0,NULL,NULL,NULL,struct timeval *tv);  
 
  可以利用select实现sleep()的功能,它将不会等待任何事件发生。 
 
4.int nanosleep(struct timespec *req,struct timespec *rem); 
  nanosleep会沉睡req所指定的时间,若rem为non-null,而且没睡饱,将会把要补眠的时间放在rem上。

~~~~~~~~~~~~~~~~~~~~~~~~~~
实际上用
select是万能的,下面的是一个使用select的例子:

#include
#include
 
void Sleep(int iSec,int iUsec)
{
       struct timeval tv;
      tv.tv_sec=iSec;
      tv.tv_usec=iUsec;
      select(0,NULL,NULL,NULL,&tv);
}
iSec 为延时秒数,Usec为延时微秒数.

注:
1秒=1000毫秒=1000000微秒=1000000000纳秒=1000000000000皮秒=1000000000000000飞秒
1s=1000ms=1000000us=1000000000ns=1000000000000ps=1000000000000000fs



内核空间:
内核里面已经实现了延时函数.
#include
udelay(int n);  延时n微秒
mdelay(int n);  延时n毫秒
ndelay(int n);  延时n纳秒
阅读(4446) | 评论(1) | 转发(1) |
0

上一篇:SPI 四种模式

下一篇:进程间通信方式比较

给主人留下些什么吧!~~

hlzembedded2011-04-22 21:56:04

其实还要区分可被调度和不可被调度的情况。