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') ...
随机推荐
- emoji表情键盘 回退删除方法
- iOS8模拟器键盘弹不出来
command + k 或 command + shift + k 切换到模拟器键盘 其默认是Mac键盘
- Week2(9月19日):增加一个CodeFirst的例子来说明
Part I:提问 =========================== 1.上堂课中我们使用了()数据库,它是()可部署的,只需要将相应的()文件添加到应用程序的()文件夹,就可以使用了,该数据 ...
- 如何将一个Jsp网站打包发布(发布为War文件)
链接地址:http://blog.csdn.net/luohuijun619/article/details/4867131 版权声明:本文为博主原创文章,未经博主允许不得转载. 网站做完后,并不是直 ...
- mysql如何开启远程连接
链接地址:http://jingyan.baidu.com/article/046a7b3ed85f3ef9c27fa9dc.html 大家在公司工作中,经常会遇到mysql数据库存储于某个人的电脑上 ...
- Solr部署详解
Solr部署详解 时间:2013-11-24 方式:转载 目录 1 solr概述 1.1 solr的简介 1.2 solr的特点 2 Solr安装 2.1 安装JDK 2.2 安装Tomcat 2.3 ...
- 7款Linux下阅读PDF的阅读器。
5款Linux下阅读PDF的阅读器.1. Mupdf:link 2. Adobe Reader:link 3. Foxit Reader:link 4.Evince:link 5. Okular:li ...
- 基于visual Studio2013解决C语言竞赛题之0907删除记录
题目
- uoj Goodbye Jiawu
这次比赛真是太伤我心了. 比(惨)赛(不)结(忍)果(睹) 完挂感言 uoj round 5已经挂了一次了,没想到还要再挂第二次. 这次比赛的期望得分是\(100+100+100+70+10\)的.没 ...
- ecosphere是什么意思_ecosphere的翻译_音标_读音_用法_例句 - 必应 Bing 词典
ecosphere是什么意思_ecosphere的翻译_音标_读音_用法_例句 - 必应 Bing 词典 ecosphere