QNX系统-关于delay函数与sleep函数的区别
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 time
Synopsis:
#include <unistd.h> unsigned int delay( unsigned int duration );
Arguments:
- duration
- The number of milliseconds for which to suspend the calling thread from execution.
Library:
libc
Use 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 time
Synopsis:
#include <unistd.h> unsigned int sleep( unsigned int seconds );
Arguments:
- seconds
- The number of realtime seconds that you want to suspend the thread for.
Library:
libc
Use 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;
}
QNX系统-关于delay函数与sleep函数的区别的更多相关文章
- Sql server函数的学习1(系统变量、错误函数、转换函数)
一.系统变量的介绍和使用 1.@@ERROR 变量 2.@@SERVICENAME 变量 3.@@TOTAL_ERRORS 变量 4.@@TOTAL_READ 变量 5.@@VERSION 变量 二. ...
- PHP学习之[第05讲]PHP5.4 循环结构、系统函数和自定义函数
一.while/for/break/continue: while (expr){ statements } for (expr1:expr2:expr3){ statement } break n ...
- ylb:SQLServer常用系统函数-字符串函数、配置函数、系统统计函数
原文:ylb:SQLServer常用系统函数-字符串函数.配置函数.系统统计函数 ylbtech-SQL Server:SQL Server-SQLServer常用系统函数 -- ========== ...
- Window系统、主函数和窗体函数这三者之间的关系
理解Window系统.主窗体.窗体函数这三者之间的关系,对于编写Windows程序十分重要. 主函数和窗体函数都是由Windows系统来调用的函数.仅仅只是主函数是程序启动之后.系统首先调用的函数: ...
- oracle系统函数(日期函数)
oracle系统函数(日期函数) 调用日期函数时,首先要明确两个概念,时间戳和日期是不同的,日期中包括年月日但不包括小时分钟秒,时间戳包括年月日小时分钟秒.在oracle中,一般情况下,函数中包含da ...
- 【教训】null == '',改造ThinkSNS 系统里面的一个缓存管理函数S()后,留下一个大bug
本来想简化 ThinkSNS 系统里面的一个缓存管理函数: <?php /** * 用来对应用缓存信息的读.写.删除 * $expire = null/0 表示永久缓存,否则为缓存有效期 */ ...
- sql server 系统常用函数:聚合函数 数学函数 字符串函数 日期和时间函数和自定义函数
一.系统函数 1.聚合函数 聚合函数常用于GROUP BY子句,在SQL Server 2008提供的所有聚合函数中,除了COUNT函数以外,聚合函数都会忽略空值AVG.COUNT.COUNT_BIG ...
- Delphi - Windows系统下,Delphi调用API函数和7z.dll动态库,自动把文件压缩成.tar.gz格式的文件
项目背景 应欧美客户需求,需要将文件压缩成.tar.gz格式的文件,并上传给客户端SFTP服务器. 你懂的,7-Zip软件的显著特点是文件越大压缩比越高,在Linux系统上相当于我们Windows系统 ...
- SQL Server系统函数:字符串函数
原文:SQL Server系统函数:字符串函数 1.字符转化为ASCII,把ASCII转化为字符,注意返回的值是十进制数 select ASCII('A'),ASCII('B'),ASCII('a') ...
随机推荐
- [原]详解如何将cocos2dx项目编译到Android平台上的(方式一:Cywin+NDK)
链接地址:http://m.blog.csdn.net/blog/yhc13429826359/29357815 2014-6-8阅读578 评论0 前言:cocos2dx作为一个开源的移动2D游戏框 ...
- [Swust OJ 781]--牛喝水
Time limit(ms): 1000 Memory limit(kb): 65535 The cows have a line of 20 water bowls from which the ...
- Python基础2:反射、装饰器、JSON,接口
一.反射 最近接触到python的反射机制,遂记录下来已巩固.但是,笔者也是粗略的使用了__import__, getattr()函数而已.目前,笔者的理解是,反射可以使用户通过自定义输入来导入响应的 ...
- poj 3370 鸽笼原理知识小结
中学就听说过抽屉原理,可惜一直没机会见识,现在这题有鸽笼原理的结论,但其实知不知道鸽笼原理都可以做 先总结一下鸽笼原理: 有n+1件或n+1件以上的物品要放到n个抽屉中,那么至少有一个抽屉里有两个或两 ...
- 年度酷工作---高级数据工程师(公司靠谱,技术强悍,产品牛叉,福利有干货) 关键词:7000万用户、五星级厨师、住房补助 - V2EX
年度酷工作---高级数据工程师(公司靠谱,技术强悍,产品牛叉,福利有干货) 关键词:7000万用户.五星级厨师.住房补助 - V2EX 年度酷工作---高级数据工程师(公司靠谱,技术强悍,产品牛叉,福 ...
- js 中实现sleep函数
除了Narrative JS,jwacs(Javascript With Advanced Continuation Support)也致力于通过扩展JavaScript语法来避免编写让人头痛的异步调 ...
- stm32之CAN总线基础
can总线协议概述: CAN是Controller Area Network的缩写,由德国博世公司开发:CAN通过ISO11891以及ISO11519进行了标准化: CAN总线的特点: 1.多 ...
- awk 的逻辑运算字符
既然有需要用到 "条件" 的类别,自然就需要一些逻辑运算啰-例如底下这些:运算单元代表意义> 大于小于>= 大于或等于小于或等于== 等于!= 不等于值得注意的是那个 ...
- ORACLE FLASHBACK DATABASE 知识整理
1.知识储备 1) 只有SYSDBA有权执行,闪回前一定要记录当前SCN 2) 需要停机,并要求处于ARCHIVELOG模式中 3) 闪回日志不能被复用和归档,是自动管理的.RVWR ...
- PCB设计资料:看到最后才知道是福利
參考资料 通过以下的关键词直接从网络上Google或Baidu就能非常easy的找到以下的资料,这里仅仅是以參考文献的方式做一个整理以及简单的说明. 刘雅芳,张俊辉. 抗干扰角度分析六层板的布线技巧. ...