seeseadream
驱动牛犊
驱动牛犊
  • 注册日期2003-10-06
  • 最后登录2005-01-24
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:6161回复:8

如何实现微秒级的线程休眠?

楼主#
更多 发布于:2004-08-12 21:30
各位大虾,我在windows 98下,做一个DLL,需要将线程休眠几十微秒,
我现在用Sleep(),但它是毫秒级的,然后我又用QueryPerformanceCounter(),但只能实现延时,如何才能实现微秒级的线程休眠呢?请指教,谢谢!!
愿与你分享成功的喜悦、失败的悲哀!
Sundsea
驱动老牛
驱动老牛
  • 注册日期2003-05-06
  • 最后登录2012-06-05
  • 粉丝0
  • 关注0
  • 积分2分
  • 威望35点
  • 贡献值0点
  • 好评度15点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2004-08-18 21:06
微秒级的应该就是实时操作系统能够达到,象Windows这种操作系统,是达不到的.
usb_anywhere
驱动小牛
驱动小牛
  • 注册日期2003-07-29
  • 最后登录2005-11-22
  • 粉丝0
  • 关注0
  • 积分3分
  • 威望1点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2004-09-02 10:46
使用空循环语句计算一下执行所用时间是否合适即可
驱网是你们的,也是我们的,归根结底还是大家的!
ebyte
驱动牛犊
驱动牛犊
  • 注册日期2002-11-20
  • 最后登录2006-10-08
  • 粉丝0
  • 关注0
  • 积分5分
  • 威望1点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地板#
发布于:2004-09-04 11:06
从网上下载了一个可以显示 ns 级的程序源码,不知是否可用来休眠,不过精确的延时大概可以做到的
附件名称/大小 下载次数 最后更新
2004-09-04_CHighTimer.rar (2KB)  137
???
Fang
驱动牛犊
驱动牛犊
  • 注册日期2001-06-12
  • 最后登录2010-08-10
  • 粉丝0
  • 关注0
  • 积分2分
  • 威望13点
  • 贡献值0点
  • 好评度2点
  • 原创分0分
  • 专家分0分
地下室#
发布于:2005-06-29 18:49
任何操作系统都不能实现微秒级的sleep,即使是实时操作系统如vxworks。在线程/进程/任务上sleep都是毫秒级的,而且非常不精确。线程/进程/任务时间片大多在20毫秒左右。
要实现微秒级的等待,唯一的方法是在ISR中运行,计算你使用的CPU的主频和nop指令的时钟周期,循环运行nop指令,才可以精确调整到微秒级。
Leonsoft
驱动小牛
驱动小牛
  • 注册日期2003-05-08
  • 最后登录2012-08-11
  • 粉丝1
  • 关注0
  • 积分21分
  • 威望281点
  • 贡献值1点
  • 好评度103点
  • 原创分0分
  • 专家分0分
5楼#
发布于:2005-07-01 14:05
Each time the clock interrupts, the clock-interrupt routine deducts a fixed value (3) from the thread quantum. If there is no remaining thread quantum, the quantum end processing is triggered and another thread might be selected to run. On Windows 2000 Professional, because 3 is deducted each time the clock interrupt fires, by default a thread runs for 2 clock intervals; on Windows 2000 Server, by default a thread runs for 12 clock intervals.

The length of the clock interval varies according to the hardware platform. The frequency of the clock interrupts is up to the HAL, not the kernel. For example, the clock interval for most x86 uniprocessors is 10 milliseconds, and for most x86 multiprocessors, 15 milliseconds.

by default a thread runs for 2 clock intervals; on Windows 2000 Server, by default a thread runs for 12 clock intervals.

KeDelayExecutionThread routine puts the current thread into an alertable or nonalertable wait state for a given interval.  in units of 100 nanoseconds, for which the wait is to occur.
I will do the best with what the God gave me.
computer00
驱动小牛
驱动小牛
  • 注册日期2004-09-27
  • 最后登录2009-08-22
  • 粉丝0
  • 关注0
  • 积分1002分
  • 威望120点
  • 贡献值0点
  • 好评度110点
  • 原创分0分
  • 专家分0分
6楼#
发布于:2007-03-28 22:53
把中断关掉,然后使用指令运行时间来延迟.
博客Http://computer00.21ic.org
libnd
驱动牛犊
驱动牛犊
  • 注册日期2006-09-28
  • 最后登录2009-02-23
  • 粉丝0
  • 关注0
  • 积分2分
  • 威望3点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
7楼#
发布于:2008-09-21 17:54
只能实现延时
liuyan1
驱动老牛
驱动老牛
  • 注册日期2001-08-27
  • 最后登录2023-04-18
  • 粉丝0
  • 关注0
  • 积分1031分
  • 威望477点
  • 贡献值0点
  • 好评度187点
  • 原创分0分
  • 专家分0分
  • 社区居民
8楼#
发布于:2008-09-22 08:35
98下还真不好
楼上的客,楼下的客,听我老坎说明白,要苛屎有草纸,不要扯我的麦席子,要苛尿有夜壶,不要在床上划地图。
游客

返回顶部