本文主要是介绍_beginthreadex用法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
头文件:#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 );
}
这篇关于_beginthreadex用法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!