日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

QNX系统-关于delay函数与sleep函数的区别

發布時間:2024/1/4 综合教程 32 生活家
生活随笔 收集整理的這篇文章主要介紹了 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:

durationThe 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:

secondsThe 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函数的区别的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。