//test thread
#include
<windows.h>#include
<stdio.h>#define
MAX_NUM 5typedef
struct TEST_STRUCT //{
DWORD i;
DWORD dwRandom;
}TEST_STRUCT,*TEST_PTR;
DWORD WINAPI ThreadProc(LPVOID lpParameter)
//{
TEST_PTR testData;
testData = (TEST_PTR)lpParameter;
//printf(
"UID=%u,%u,%u\n" ,GetCurrentThreadId(),testData->i,testData->dwRandom);HeapFree(GetProcessHeap(),0,testData);
// return 0;}
int
main(){
TEST_PTR testData;
DWORD dwThreadID[MAX_NUM];
HANDLE hThread[MAX_NUM];
for ( int i=0;i<MAX_NUM;i++){
//testData = (TEST_PTR)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,
sizeof (TEST_STRUCT)); if (testData == NULL) //{
printf(
"heapAlloc error!\n" );}
testData->i = i;
testData->dwRandom = rand();
/ ///1: 201M 3 4 ///5 6TIDhThread[i] = CreateThread(NULL,0,ThreadProc,testData,0,&dwThreadID[i]);
if (hThread[i] == NULL){
printf(
"create thread error!\n" );}
///MAX_NUMWaitForMultipleObjects(MAX_NUM,hThread,TRUE,INFINITE);
for ( int i=0;i<MAX_NUM;i++){
CloseHandle(hThread);
//}
}
return 0;}