// one.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
using namespace std;
BOOL repeat = true;
DWORD WINAPI MyThread1(LPVOID lpParameter)
{
while(repeat)
{
cout<<"how are you ?"<<endl;
Sleep(1);
}
DWORD exitCode;
ExitThread(exitCode);
return 0;
}
DWORD WINAPI MyThread2(LPVOID lpParameter)
{
while(repeat)
{
cout<<"very well !"<<endl;
Sleep(1);
}
DWORD exitCode;
ExitThread(exitCode);
return 0;
}
DWORD WINAPI MyThread3(LPVOID lpParameter)
{
while(repeat)
{
cout<<"very well !"<<endl;
Sleep(1);
}
DWORD exitCode;
ExitThread(exitCode);
return 0;
}
DWORD WINAPI KillThread(LPVOID lpParameter)
{
repeat = false;
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
HANDLE handle1,handle2,handle3;
DWORD dw1,dw2,dw3;
handle1 = CreateThread(NULL,0,MyThread1,NULL,0,&dw1);
if(handle1== NULL)
{
cout<<"线程1创建失败!!"<<endl;
return -1;
}
handle2 = CreateThread(NULL,0,MyThread2,NULL,0,&dw2);
if(handle2== NULL)
{
cout<<"线程2创建失败!!"<<endl;
return -1;
}
handle3 = CreateThread(NULL,0,MyThread3,NULL,0,&dw3);
if(handle3== NULL)
{
cout<<"线程1创建失败!!"<<endl;
return -1;
}
CloseHandle(handle1);
CloseHandle(handle2);
CloseHandle(handle3);
getchar();
return 0;
}