文章編號: 951322 - 上次校閱: 2008年4月30日 - 版次: 1.0

與在 Windows XP、 Windows Server 2003 或 Windows Vista pseudohandles WaitForMultipleObjects() 函式無法正確運作

系統提示本文適用於您使用的作業系統之外的作業系統。與您不相關的文章內容已停用。
全部展開 | 全部摺疊

徵狀

WaitForMultipleObjects() 功能沒有正確地運作與 pseudohandles 在 Windows XP、 Windows Server 2003 或 Windows Vista 一起。

請考慮
int _tmain(int argc, _TCHAR* argv[])
{
      
      HANDLE hnd[1]; 
	long res; 
	hnd[0] = GetCurrentProcess(); 

        res = WaitForMultipleObjects(1, hnd, FALSE, 3000);
      return 0;
}
執行範例程式碼後您預期函式,以傳回三秒之後。 在下列範例程式碼。但是,它會傳回 WAIT_FAILED"錯誤,而且它不會等到。

其他可行方案

如果要解決這個問題,使用 DuplicateHandle() 函數來將 pseudohandles 轉換為真實的處理序控制代碼。

例如使用下列的範例程式碼
int _tmain(int argc, _TCHAR* argv[])
{
      
      HANDLE hnd[1]={0};
      long res; 
      HANDLE Threadhandle = ::GetCurrentThread();
      
      DuplicateHandle(GetCurrentProcess(), Threadhandle, 
      GetCurrentProcess(),
      &hnd[0], 
      0,
      FALSE,
      DUPLICATE_SAME_ACCESS);

      res = WaitForMultipleObjects(1, hnd, TRUE, 10000);

      return 0;
}

其他相關資訊

pseudohandle 是解譯成目前的執行緒或處理序控制代碼的特殊常數,就會發生這個問題。呼叫的執行緒可以使用此控制代碼,來指定本身需要執行緒控制碼時。這些控制代碼無法參考由其他執行緒。一個 pseudohandle 都會解譯為參考至正在使用它的執行緒。

pseudohandle 沒有不再需要時被關閉。這個控制代碼為呼叫 CloseHandle() 函式沒有任何作用。

處理程序會使用 GetCurrentProcess() 函式或 GetCurrentHandle() 函式來取得控點以本身。這個控制代碼是一個 pseudohandle。不過,DuplicateHandle() 函式轉換成真正的處理序控制代碼。

這篇文章中的資訊適用於:
  • Microsoft Windows Server 2003, Standard Edition (32-bit x86)
  • Microsoft Windows Server 2003, Enterprise Edition (32-bit x86)
  • Microsoft Windows Server 2003, Datacenter Edition (32-bit x86)
  • Microsoft Windows Server 2003, Standard x64 Edition
  • Microsoft Windows Server 2003, Enterprise x64 Edition
  • Microsoft Windows Server 2003, Datacenter x64 Edition
  • Microsoft Windows Server 2003, Enterprise Edition for Itanium-based Systems
  • Microsoft Windows Server 2003, Datacenter Edition for Itanium-Based Systems
  • Microsoft Windows XP Professional
  • Microsoft Windows XP Home Edition (家用版)
  • Windows Vista 商用入門版
  • Windows Vista 商用進階版
  • Windows Vista 家用入門版
  • Windows Vista 家用進階版
  • Windows Vista 旗艦版
  • Windows Vista 商用入門 64 位元版
  • Windows Vista 商用進階 64 位元版
  • Windows Vista 家用入門 64 位元版
  • Windows Vista 家用進階 64 位元版
  • Windows Vista 旗艦 64 位元版
關鍵字:?
kbmt kbexpertiseinter kbtshoot kbprb KB951322 KbMtzh
機器翻譯機器翻譯
重要:本文是以 Microsoft 機器翻譯軟體翻譯而成,而非使用人工翻譯而成。Microsoft 同時提供使用者人工翻譯及機器翻譯兩個版本的文章,讓使用者可以依其使用語言使用知識庫中的所有文章。但是,機器翻譯的文章可能不盡完美。這些文章中也可能出現拼字、語意或文法上的錯誤,就像外國人在使用本國語言時可能發生的錯誤。Microsoft 不為內容的翻譯錯誤或客戶對該內容的使用所產生的任何錯誤或損害負責。Microsoft也同時將不斷地就機器翻譯軟體進行更新。
按一下這裡查看此文章的英文版本:951322? (http://support.microsoft.com/kb/951322/en-us/ )
Microsoft及(或)其供應商不就任何在本伺服器上發表的文字資料及其相關圖表資訊的恰當性作任何承諾。所有文字資料及其相關圖表均以「現狀」供應,不負任何擔保責任。Microsoft及(或)其供應商謹此聲明,不負任何對與此資訊有關之擔保責任,包括關於適售性、適用於某一特定用途、權利或不侵權的明示或默示擔保責任。Microsoft及(或)其供應商無論如何不對因或與使用本伺服器上資訊或與資訊的實行有關而引起的契約、過失或其他侵權行為之訴訟中的特別的、間接的、衍生性的損害或任何因使用而喪失所導致的之損害、資料或利潤負任何責任。