該樓層疑似違規已被系統折疊 隐藏此樓檢視此樓
Windows作業系統,C語言實作多線程:
#include
#include
DWORD APIENTRY ThreadOne ( LPVOID threadArg )
{
printf ( "線程開始啦,參數是:%s\n" , (char *)threadArg );
return 0;
}
int main ( void )
{
HANDLE hThread;
DWORD ThreadID;
DWORD waitingResult;
DWORD threadExitCode;
char * aMessage = "這是線程的參數" ;
hThread = CreateThread ( NULL, 0L, ThreadOne, (LPVOID)aMessage, 0L, &ThreadID );
if ( hThread == NULL )
{
printf ("線程ThreadOne建立失敗。錯誤代碼:%lu\n", GetLastError() );
return EXIT_FAILURE ;
}
waitingResult = WaitForSingleObject ( hThread, INFINITE );
if ( waitingResult == WAIT_FAILED )
{
printf ( "等待線程退出等待失敗。錯誤代碼:%lu\n" , GetLastError() ) ;
return EXIT_FAILURE ;
}
if ( GetExitCodeThread ( hThread , &threadExitCode ) )
printf ( "線程的傳回值是%lu\n", threadExitCode ) ;
else
printf ( "擷取線程的傳回值擷取失敗。錯誤代碼:%lu\n" , GetLastError() ) ;
return EXIT_SUCCESS ;
}