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') ...
随机推荐
- 【QT相关】Qt Widgets Module
Qt Widgets Module:提供了一些列UI元素. 使用: //头文件包含 #include <QtWidgets> //链接模式,在.pro文件中添加行: QT += widge ...
- CentOS用yum安装搭建LAMP
#1.安装Apache yum install httpd httpd-devel #启动apache /etc/init.d/httpd start #设为开机启动: chkconfig httpd ...
- USACO Healthy Holsteins DFS
使用排列组合,遍历所有可能的情况C(1)+C(2)+C(3)……C(n)= 2^G种组合 数据规模不大,暴力过去最多也就是2^15 = 23768种情况 所以就暴力咯,不过还是Debug了一会 Sou ...
- RunLoop学习总结
开始 很久之前就看了一次YY的文章,没看懂.后来又看了sunny的视频和叶孤城的直播的视频,找了很多资料,对RunLoop也越来越清晰,然后又看了两三次YY的文章,虽然还没完全看懂,不得不说写的非常好 ...
- freemarker序列的拆分
freemarker序列的拆分 1.简易说明 序列的拆分能够是数组.字符串.布尔值等等 2.实现源代码 <#--freemarker序列的拆分--> ${"hudjfkskhd你 ...
- HDU 4617Weapon(两条异面直线的距离)
Weapon Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Sub ...
- javascript每日一练(十)——运动二:缓冲运动
一.缓冲运动 实现原理:(目标距离-当前距离) / 基数 = 速度(运动距离越大速度越小,运动距离和速度成反比) (500 - oDiv.offsetLeft) / 7 = iSpeed; 需要注意: ...
- 简单描述RAID级别:
简单描述RAID级别: RAID 0 是俩盘一起读写,如果一个坏了那么数据全丢失: RAID 1是一块写,一块用来备份,坏一块无所谓: RAID 2 ,3 ,4 不常用: 最常用的就是RAID 5和R ...
- 《音乐商店》第4集:自动生成StoreManager控制器
一.自动生成StoreManager控制器 二.查看 StoreManager 控制器的代码 现在,Store Manager 控制器中已经包含了一定数量的代码,我们从头到尾重新过一下. 1.访问数据 ...
- Mac OSX的开机启动配置
Login Items Mac OSX的当前用户成功登录后启动的程序,该类别的启动项配置文件存放在~/Library/Preferences/com.apple.loginitems.plist,所以 ...