16079|56

76

帖子

0

TA的资源

一粒金砂(初级)

楼主
 

sleep函数是如何实现的? [复制链接]

是这样的,俺的2440的应用程序调用这个sleep函数,非常不准确。sleep(500)的效果相与sleep(100)的效果,也就是说这个时间变快了。但是另外一5.0 BSP却正常,我看了一下帮助,没有讲这个函数是如何实现的,请问这个函数如此不准确,是什么原因。
多谢各位了。

最新回复

哎,我正郁闷我水平差啊。慢慢学习吧。 揭帖,虽然不懂事咋回事,你知道的就帮帮我吧,感激不尽。  详情 回复 发表于 2009-9-11 18:57
点赞 关注

回复
举报

84

帖子

0

TA的资源

一粒金砂(初级)

沙发
 
This function suspends the execution of the current thread for a specified interval.

void Sleep(
  DWORD dwMilliseconds
);
Parameters
dwMilliseconds
[in] Specifies the time, in milliseconds, for which to suspend execution.
A value of zero causes the thread to relinquish the remainder of its time slice to any other thread of equal priority that is ready to run. If no other threads of equal priority are ready to run, the function returns immediately, and the thread continues execution.

A value of INFINITE causes an infinite delay.

Return Values
None.

Remarks
A thread can relinquish the remainder of its time slice by calling this function with a sleep time of zero milliseconds.

Calling Sleep(INFINITE) is different on Windows CE-based platforms than it is for Windows-based desktop platforms. For Windows CE-based platforms, Sleep(INFINITE) is equivalent to calling SuspendThread(GetCurrentThread()). This means that the thread suspend count is incremented from 0 to 1 and can be resumed, or woken up, by another thread that calls ResumeThread on the sleeping thread. A Sleep(INFINITE) call on Windows-based desktop platforms is not a SuspendThread call, and calling ResumeThread on the sleeping thread does not resume the thread.

Be careful when using Sleep and code that directly or indirectly creates windows. An example of code that indirectly creates windows is COM CoInitialize.

If a thread creates windows, it must process messages. Message broadcasts are sent to all windows in the system.

A thread that uses Sleep with an infinite delay can cause the system to deadlock. Therefore, if you have a thread that creates windows, use MsgWaitForMultipleObjects or MsgWaitForMultipleObjectsEx, rather than Sleep.

Requirements
OS Versions: Windows CE 1.0 and later.
Header: Winbase.h.
Link Library: Coredll.lib.

PB帮助对于该函数实现是只字未提。找不到原因,只能来打扰各位了。
 
 

回复

82

帖子

0

TA的资源

一粒金砂(初级)

板凳
 
在PB帮助中找到
The timer is always set to 1 millisecond under default working conditions when there are threads to schedule. Therefore, you can call Sleep(1) and expect to receive approximately 1 ≤ n ≤ 2 millisecond (ms) accuracy if the thread is the highest priority thread running on the system.

也就是说sleep函数精度只是相差一毫秒级别,咋我的会这么大呢?

 
 
 

回复

87

帖子

0

TA的资源

一粒金砂(初级)

4
 
哈, 这问题我在 WinCE 3.0 遇过, 问题在你的 Kernel 内的 system time tick 不对, 通常是因为 OEMIdle 有问题.

Paul, Chao @ Techware
 
 
 

回复

69

帖子

0

TA的资源

一粒金砂(初级)

5
 
引用 3 楼 paul_chao 的回复:
哈, 这问题我在 WinCE 3.0 遇过, 问题在你的 Kernel 内的 system time tick 不对, 通常是因为 OEMIdle 有问题.

Paul, Chao @ Techware



但是还是跑的蛮好啊。咋会这样呢。多谢paul,chao提示。
要不然真不知道咋回事呢。
 
 
 

回复

69

帖子

0

TA的资源

一粒金砂(初级)

6
 
这个要看系统的时钟click的
 
 
 

回复

81

帖子

0

TA的资源

一粒金砂(初级)

7
 
引用 5 楼 iwillbeback008 的回复:
这个要看系统的时钟click的


但是我检查了,没有问题啊
 
 
 

回复

98

帖子

0

TA的资源

一粒金砂(初级)

8
 
咋回事,我现在发帖越来越少人回了。why?
 
 
 

回复

76

帖子

0

TA的资源

一粒金砂(初级)

9
 
引用 7 楼 gooogleman 的回复:
咋回事,我现在发帖越来越少人回了。why?



因为越来越专业了
 
 
 

回复

68

帖子

0

TA的资源

一粒金砂(初级)

10
 
这个还跟系统中的其它线程有关系吧。


Sleep 一调用,线程马上放弃时间片;

至于什么时候再进来,那要看其它线程的运行情况了;

操作系统只能给个大概时间,一般来说是滞后的。




我是这么认为的!
 
 
 

回复

70

帖子

0

TA的资源

一粒金砂(初级)

11
 
学习了~~
 
 
 

回复

77

帖子

0

TA的资源

一粒金砂(初级)

12
 
引用 9 楼 zaodt 的回复:
这个还跟系统中的其它线程有关系吧。


Sleep 一调用,线程马上放弃时间片;

至于什么时候再进来,那要看其它线程的运行情况了;

操作系统只能给个大概时间,一般来说是滞后的。


我是这么认为的!


我不是滞后,我是超前很多哦,嘿嘿,所以感觉特别奇怪。
 
 
 

回复

54

帖子

0

TA的资源

一粒金砂(初级)

13
 
这个大概就是为什么驱动里面尽量少用sleep,而用PXA_OST_DelayMilliSeconds(100);  这些函数了吧,不准
 
 
 

回复

85

帖子

0

TA的资源

一粒金砂(初级)

14
 
还有我严重同意你现在回帖人少的现象,已经几个帖子无满意结贴了,哎。。。。
 
 
 

回复

60

帖子

0

TA的资源

一粒金砂(初级)

15
 
Sleep应该会调用系统的API,可能系统某些地方会影响它
个人猜测^@^ 
 
 
 

回复

61

帖子

0

TA的资源

一粒金砂(初级)

16
 
引用 12 楼 lesho 的回复:
这个大概就是为什么驱动里面尽量少用sleep,而用PXA_OST_DelayMilliSeconds(100);? 这些函数了吧,不准


我是在应用里面。驱动不会这样用的。影响性能。

shuiyan等人忙着项目没有来。
 
 
 

回复

76

帖子

0

TA的资源

一粒金砂(初级)

17
 
这个收藏一下吧,后边继续关注,回答的少是因为你问的问题越来越难了!
 
 
 

回复

69

帖子

0

TA的资源

一粒金砂(初级)

18
 
水平不行,帮不上忙,顶一下吧,确实越来越专业了
 
 
 

回复

48

帖子

0

TA的资源

一粒金砂(初级)

19
 
如果自己写个mswait的函数,直接从OST产生延时

会出现同样的问题吗
 
 
 

回复

58

帖子

0

TA的资源

一粒金砂(初级)

20
 
引用 18 楼 suwyhoho 的回复:
如果自己写个mswait的函数,直接从OST产生延时

会出现同样的问题吗

这个不会哦。
 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/8 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表