阅读:6263回复:8
如何实现微秒级的线程休眠?
各位大虾,我在windows 98下,做一个DLL,需要将线程休眠几十微秒,
我现在用Sleep(),但它是毫秒级的,然后我又用QueryPerformanceCounter(),但只能实现延时,如何才能实现微秒级的线程休眠呢?请指教,谢谢!! |
|
|
沙发#
发布于:2004-08-18 21:06
微秒级的应该就是实时操作系统能够达到,象Windows这种操作系统,是达不到的.
|
|
板凳#
发布于:2004-09-02 10:46
使用空循环语句计算一下执行所用时间是否合适即可
|
|
|
地板#
发布于:2004-09-04 11:06
从网上下载了一个可以显示 ns 级的程序源码,不知是否可用来休眠,不过精确的延时大概可以做到的
|
|
|
地下室#
发布于:2005-06-29 18:49
任何操作系统都不能实现微秒级的sleep,即使是实时操作系统如vxworks。在线程/进程/任务上sleep都是毫秒级的,而且非常不精确。线程/进程/任务时间片大多在20毫秒左右。
要实现微秒级的等待,唯一的方法是在ISR中运行,计算你使用的CPU的主频和nop指令的时钟周期,循环运行nop指令,才可以精确调整到微秒级。 |
|
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. |
|
|
6楼#
发布于:2007-03-28 22:53
把中断关掉,然后使用指令运行时间来延迟.
|
|
|
7楼#
发布于:2008-09-21 17:54
只能实现延时
|
|
8楼#
发布于:2008-09-22 08:35
98下还真不好
|
|
|