我的意思是如果Sleep()的时间不是很长例如Sleep(100),
那么线程被挂起时耗费的时间和线程重新恢复执行要花费的时间
有没有可能接近100甚至超过100呢?
在哪些情况下调用这个函数才有必要呢?

解决方案 »

  1.   

    Res
    A thread can relinquish the remainder of its time slice by calling this function with a sleep time of zero milliseconds. You have to be careful when using Sleep and code that directly or indirectly creates windows. If a thread creates any windows, it must process messages. Message broadcasts are sent to all windows in the system. If you have a thread that uses Sleep with infinite delay, the system will deadlock. Two examples of code that indirectly creates windows are DDE and COM CoInitialize. Therefore, if you have a thread that creates windows, use MsgWaitForMultipleObjects or MsgWaitForMultipleObjectsEx, rather than Sleep.
      

  2.   

    不必担心
    sleep(0)都有
    或者可以写个sleep(0)
    然后profile看看,它占用了多少cpu时间
      

  3.   

    Sleep(0)是线程直接把属于自己的时间片让给下一个需要的线程
      

  4.   

    to foxmail:
    profile 是什么意思?怎么做?
      

  5.   

    为什么要用sleep,用Wait*()函数比sleep好,因为编码时不可能知道要等多久的你机上是100,可能另外机上就是1000了
      

  6.   

    project->setting->link->enable profiling
    然后build->profile
    但好像不是每个工程都能profile,有人知道什么时候一定能profile吗
      

  7.   

    我刚才用Sleep(0)好象跟不Sleep(0)一样的!!
      

  8.   

    msdnGGD
    This error can occur if the file, subdirectory, or disk on which it resides is read-only. In this case, make the file writable or move the file to a writable disk. See your operating system documentation for information on removing the read-only attribute from a file.
    This error may be caused by not having enough file handles. Close some open applications and recompile.
    Trying to open a file or directory for which you do not have permission can cause this error. Move the file to a directory where you do have access privileges, or ask your network administrator to grant you access to the file.
    If an include file could not be opened, check that the INCLUDE environment variable is set correctly and that the name of the file is spelled correctly.
    Using double quotation s around a complete path specification in a #include directive causes the standard directories to NOT be searched. See The #include Directive in the Preprocessor Reference for more information. 
      

  9.   

    用sleep吧,没有什么负面影响,而wait等会造成消息泄漏,程序的逻辑处理不好还会造成混乱