我最近寫一個小的C語言專案需要使用多執行緒,我對于C語言多執行緒是一個小白,找了各種代碼實體來研究,但是我每次復制別人的代碼來測驗的時候,我的vc都顯示error C2660: '_beginthreadex' : function does not take 0 parameters,這到底是為什么呢,我的工程設定也設定了多執行緒了Debug Multithreaded,我把代碼貼一些吧,求求哪位大哥的解答能教教我C語言多執行緒的使用我也非常感謝,非常的感謝,很急5555555
// crt_begthrdex.cpp
// compile with: /MT
#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" );
// Create the second thread.
hThread = (HANDLE)_beginthreadex( NULL, 0, &SecondThreadFunc, NULL, 0, &threadID );
// Wait until second thread terminates. If you comment out the line
// below, Counter will not be correct because the thread has not
// terminated, and Counter most likely has not been incremented to
// 1000000 yet.
WaitForSingleObject( hThread, INFINITE );
printf( "Counter should be 1000000; it is-> %d\n", Counter );
// Destroy the thread object.
CloseHandle( hThread );
return 0;
}
uj5u.com熱心網友回復:
CreateThread也可以用啊
uj5u.com熱心網友回復:
但是CreateThread沒有_beginthreadex執行緒安全啊
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/41189.html
標籤:C++ 語言
上一篇:新人小白問問題希望有大神來看~
下一篇:求C語言大神相助!
