如果写一个while(1);
那么运行时候cpu肯定是100%。但是在运行win32程序时候,
消息循环也是如此执行
while(ture)
{
peekMessage(..
...
}
但是程序运行时候cpu占用率却不是100%,
请问是为什么

解决方案 »

  1.   

    peekMessage中有idle,没有消息就切换线程了
      

  2.   

    上面为无条件死循环,下面为消息响应,也就是不断轮循队列中消息,我试了下,如果此程序在前台,也就是获得焦点时,CPU占满了(不为100%,其和加起来也差不多,有这么多进程...你优先级不一定最高)但如果其在后台运行(没获得焦点时,基本上没占CPU,因为没什么消息通过,需要系统处理)
      

  3.   

    Unlike the GetMessage function, the PeekMessage function does not wait for a message to be placed in the queue before returning. peekmessage没有取到消息会继续执行其后的代码