От: | ilvi | ||
Дата: | 11.09.09 02:23 | ||
Оценка: |
#include "stdafx.h"
#include <atlbase.h>
#include <iostream>
using namespace std;
unsigned __stdcall second_thread(void*)
{
int i = 0;
while(i < 100)
{
cout << "still alive " << endl;
++i;
Sleep(100);
}
_endthreadex( 0 );
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
cout << "create second thread" << endl;
unsigned threadID;
HANDLE hThread = (HANDLE)_beginthreadex( NULL, 0, &second_thread, NULL, 0, &threadID );
//WaitForSingleObject( hThread, INFINITE ); //Если раскоментировать эту строчку, то второй поток естественно отрабатывает полностью
CloseHandle(hThread);
cout << "exit " << endl;
return 0;
}
create second thread
exit still alive
Для продолжения нажмите любую клавишу . . .