// UnitTestDemo.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "windows.h"
#include <string>
#include "process.h"
using namespace std;
#define NUM 5
//DWORD WINAPI ThreadFunc(LPVOID lp)
//{
// printf("子线程的线程ID = %d\r\n", GetCurrentThreadId());
// getchar();
// return 0;
//}
unsigned int _stdcall ThreadFunc(LPVOID lp)
{
printf("我是线程 %d\r\n", GetCurrentThreadId());
getchar();
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
// 创建单线程
//HANDLE handle = CreateThread(NULL, 0, ThreadFunc, NULL, 0, NULL);
//WaitForSingleObject(handle, INFINITE);
// 创建多个线程
HANDLE handle[NUM];
for (int i = 0; i < NUM; i++)
{
handle[i] = (HANDLE)_beginthreadex(NULL, 0, ThreadFunc, NULL, 0, NULL);
}
WaitForMultipleObjects(NUM, handle, TRUE, INFINITE);
return 0;
}
//
#include "stdafx.h"
#include "windows.h"
#include <string>
#include "process.h"
using namespace std;
#define NUM 5
//DWORD WINAPI ThreadFunc(LPVOID lp)
//{
// printf("子线程的线程ID = %d\r\n", GetCurrentThreadId());
// getchar();
// return 0;
//}
unsigned int _stdcall ThreadFunc(LPVOID lp)
{
printf("我是线程 %d\r\n", GetCurrentThreadId());
getchar();
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
// 创建单线程
//HANDLE handle = CreateThread(NULL, 0, ThreadFunc, NULL, 0, NULL);
//WaitForSingleObject(handle, INFINITE);
// 创建多个线程
HANDLE handle[NUM];
for (int i = 0; i < NUM; i++)
{
handle[i] = (HANDLE)_beginthreadex(NULL, 0, ThreadFunc, NULL, 0, NULL);
}
WaitForMultipleObjects(NUM, handle, TRUE, INFINITE);
return 0;
}