QNX系统-关于delay函数与sleep函数的区别
2015-04-02 10:27
155 查看
QNX是类unix系统。 在c语言编程过程中,往往会用到delay或者sleep延时函数。两者之间在使用上有一定的区别!!!
delay()是循环等待,该进程还在运行,占用处理器。 sleep()不同,它会被挂起,把处理器让给其他的进程。 sleep()参数指定暂停时间,单位是s delay()参数指定暂停时间,单位是ms
usleep功能: 暂停执行。 语法: void usleep(int micro_seconds); 返回值: 无 函数种类: PHP 系统功能 内容说明:本函数可暂时使程序停止执行。参数 micro_seconds 为要暂停的毫秒数(微妙还是毫秒?)。 注意:这个函数不能工作在 Windows 操作系统中。参见:usleep() 与sleep()类似,用于延迟挂起进程。进程被挂起放到reday queue。 只是一般情况下,延迟时间数量级是秒的时候,尽可能使用sleep()函数。 且,此函数已被废除,可使用nanosleep。 如果延迟时间为几十毫秒,或者更小,尽可能使用usleep()函数。这样才能最佳的利用CPU时间 delay: 函数名: delay 功 能: 将程序的执行暂停一段时间(毫秒) 用 法: void delay(unsigned milliseconds); 程序例: /* Emits a 440-Hz tone for 500 milliseconds */ #include<dos.h> int main(void) { sound(440); delay(500); nosound(); return 0; } 附:QNX下相关解释
delay()
Suspends a calling thread for a given length of timeSynopsis:
#include <unistd.h> unsigned int delay( unsigned int duration );
Arguments:
durationThe number of milliseconds for which to suspend the calling thread from execution.Library:
libcUse the -l c option to qcc to link against this library. This library is usually included automatically.
Description:
The delay() function suspends the calling thread for duration milliseconds.sleep()
Suspend a thread for a given length of timeSynopsis:
#include <unistd.h> unsigned int sleep( unsigned int seconds );
Arguments:
secondsThe number of realtime seconds that you want to suspend the thread for.Library:
libcUse the -l c option to qcc to link against this library. This library is usually included automatically.
Description:
The sleep() function suspends the calling thread until the number of realtime seconds specified by the seconds argument have elapsed, or the thread receives a signal whose action is either to terminate the process or to call a signal handler. The suspension time may be greater than the requested amount, due to the nature of time measurement (see the Tick, Tock: Understanding the Neutrino Microkernel's Concept of Time chapter of the QNX Neutrino Programmer's Guide), or due to the scheduling of other, higher priority threads by the system.Returns:
0 if the full time specified was completed; otherwise, the number of seconds unslept if interrupted by a signal.Examples:
/* * The following program sleeps for the * number of seconds specified in argv[1]. */ #include <stdlib.h> #include <unistd.h> int main( int argc, char **argv ) { unsigned seconds; seconds = (unsigned) strtol( argv[1], NULL, 0 ); sleep( seconds ); return EXIT_SUCCESS; }
相关文章推荐
- 关于 Java 的系统属性 sun.jnu.encoding 和 file.encoding 的区别
- 关于 Java 的系统属性 sun.jnu.encoding 和 file.encoding 的区别
- 关于业务用例和系统用例区别
- 关于 Java 的系统属性 sun.jnu.encoding 和 file.encoding 的区别
- 关于Android设备root权限和系统签名权限的区别问题
- 关于 Java 的系统属性 sun.jnu.encoding 和 file.encoding 的区别
- 关于 Java 的系统属性 sun.jnu.encoding 和 file.encoding 的区别
- 关于知识管理系统和信息管理系统的区别
- 关于数据库连接未及时关闭的系统报错, 以及该过程中使用DataSet和DataReader的区别
- 关于 Java 的系统属性 sun.jnu.encoding 和 file.encoding 的区别
- 关于开发支付宝与Paypal系统有何区别
- 关于c#中的消息处理函数和vc中的消息处理函数区别(引自ucucf的专栏)
- 关于在BSD系统中简单设计系统调用, --核心开发入门(2)
- 和小贺的聊天记录,关于业务用例和系统用例的一些迷惑
- 关于系统操作、多线程
- 关于C#中,继承类重写与隐藏基类方法的区别!
- 关于JAVA1.2与1.4考试的区别!
- 关于VSS系统权限设置
- 关于口令系统替代方案的初步设想
- 关于企业及时通系统中短信中心模块的分析