dongshi3605 2011-09-21 10:58
浏览 29

PHP代码解释

Can anyone explain me how usleep or sleep helps to unload the CPU.
I have written sample code as below.

while (1) // check if the data file has been modified 
{
  usleep(10000); // sleep 10ms to unload the CPU**
  clearstatcache();
  $currentmodif = filemtime($filename);
}
  • 写回答

3条回答 默认 最新

  • doudou521125 2011-09-21 11:02
    关注

    If you run usleep() the CPU will not spend time waiting around.
    Instead it will set a timer and use the extra time on other threads/programs.

    If you write code that does a lot of work to burn away the CPU time, the CPU will be working hard at that, ignoring other tasks, because it thinks it is doing useful work.
    If you use usleep the CPU (actually the OS) knows there is nothing useful to be done and will prioritize other work.

    评论

报告相同问题?

悬赏问题

  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗