_beginthreadex用法

来源:互联网 发布:网络上 蛤是啥意思 编辑:程序博客网 时间:2024/05/22 07:53

头文件:#inlude   <process.h>

设置:project   Setting   ->   C++   -> Category中选Code   Generate   -> using   runtime   lib   下选多线程模式


例子(msdn):

#include   <windows.h>  

#include   <stdio.h>  

#include   <process.h>  

   

unsigned   Counter;    
unsigned   __stdcall   SecondThreadFunc(   void*   pArguments   )  
{  
     printf(   "In   second   thread...\n"   );  
   
      while   (   Counter   <   1000000   )  
         Counter++;  
   
          _endthreadex(   0   );  
          return   0;  
  }    
   
  int   main()  
  {    
          HANDLE   hThread;  
          unsigned   threadID;  
   
          printf(   "Creating   second   thread...\n"   );  
   
          hThread   =   (HANDLE)_beginthreadex(   NULL,   0,   &SecondThreadFunc,  NULL,   0,   &threadID   );   //NULL表示无传递参数
   
          WaitForSingleObject(   hThread,   INFINITE   );  
          printf(   "Counter   should   be   1000000;   it   is->   %d\n",   Counter   );  
          
          CloseHandle(   hThread   );  
  }


原创粉丝点击