1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#include <iostream>
#include <Windows.h>
#include <process.h>
#include <stdlib.h>
using namespace std;
typedef struct struct1
{
int entier;
char* description;
}struct1;
unsigned int __stdcall thread(void *param1)
{ struct struct1 *passed_struct;
passed_struct = (struct struct1 *) param1;
cout << passed_struct->entier<<" ";
cout<< passed_struct->description<<endl;
passed_struct->entier=passed_struct->entier+1;
return(0);
}
int main()
{
int i;
HANDLE handle[5];
struct1 doublet1;
doublet1.entier=0;
doublet1.description="something";
for(i=0;i<5;i++)
{
handle[i] = (HANDLE)_beginthreadex(0, 0, &thread, (void*)&doublet1, 0, 0);
}
WaitForSingleObject( handle1[0], INFINITE );
WaitForSingleObject( handle1[1], INFINITE );
WaitForSingleObject( handle1[2], INFINITE );
WaitForSingleObject( handle1[3], INFINITE );
WaitForSingleObject( handle1[4], INFINITE );
cout <<"final value is"<<doublet1.entier<<endl;
} |
Partager