#include #include #include //thread1b.cpp typedef struct { DWORD count; DWORD size; } paramtypes; void myThread(paramtypes *params) { DWORD i,j; i=0; while (i < 50) { cout << "Here I am in thread #"<< (*params).count << "\n"; cout << " Size is " << (*params).size << "\n"; if (i%2 == 0) Sleep(1000); else Sleep(10); i++; } GlobalFree(params); } void main(void) { HANDLE myHandles[5]; //array of three handles DWORD threadID; paramtypes *params; DWORD count; int size; size=50; for (count=0; count<5; count++) { // allocate memory for a "params" structure params=(paramtypes *) GlobalAlloc(GPTR, sizeof(paramtypes)); (*params).count = count; (*params).size = size; size--; // create a thread and pass it the pointer // to its "params" struct myHandles[count]=CreateThread(0, 0, (LPTHREAD_START_ROUTINE) myThread, params, 0, &threadID); } // wait for all threads to finish execution WaitForMultipleObjects(3, myHandles, TRUE, INFINITE); }