标签:
启动5个线程,并且分别交给它们参数0~4。每一个线程打印其参数10次。
#define WIN32_LEAN_AND_MEAN
#include<stdio.h>
#include<stdlib.h>
#include<Windows.h>
DWORD WINAPI ThreadFunc(LPVOID);
int main()
{
HANDLE hThrd;
DWORD threadId;
int i;
for (i = 0; i < 5; i++)
{
hThrd = CreateThread(NULL, 0, ThreadFunc, (LPVOID)i, 0, &threadId);
if (hThrd)
{
printf("Thread launched %d \n", i);
//法二:CloseHandle(hThrd);
}
}
//wait for the threads to complete.
Sleep(2000);
return EXIT_SUCCESS;
}
DWORD WINAPI ThreadFunc(LPVOID n)
{
int i;
for (i = 0; i < 10; i++)
{
printf("%d%d%d%d%d%d%d%d\n", n, n, n, n, n, n, n, n);
}
system("pause");
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/wangfengfan1/article/details/46999379