15,471
社区成员
发帖
与我相关
我的任务
分享
#include "stdafx.h"
#include <iostream>
using namespace std;
UINT __cdecl ThreadProc(LPVOID lParam)
{
cout<<"Work thread start!!!"<<endl;
for(int i=0; i<10; i++)
{
cout<<"Thread cout: "<<i<<endl;
Sleep(500);
}
cout<<"Work thread end!!!"<<endl;
return 0;
}
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
CWinThread* pThread = AfxBeginThread(ThreadProc, NULL, THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED, NULL);
pThread->m_bAutoDelete = FALSE;
HANDLE hThread = pThread->m_hThread;
pThread->ResumeThread();
WaitForSingleObject(hThread, INFINITE);
CloseHandle(hThread);
delete pThread;
pThread = NULL;
cout<<"main thread end!"<<endl;
return 0;
}