/* * MyThread.cpp * Benjamin Bertka - 23306013 * bbertka@mss.icics.ubc.ca * * CICS505 - os6 part B */ #include "windows.h" #include #include #include #include #include "MyThread.h" #include #include using namespace std; /* a global list of MyThrads*/ MyThread *threadList; /*a global list of thread handles*/ HANDLE *handles; /* * creates a random number no larger than 10000 (1 sec) * and no smaller than 200 (msec) */ int randomWait(){ return rand() % 9800 + 200; } /* * creates a random number between 1 and max */ int randomIncrement(int max){ return rand() % max + 1; } int main(int argc, char **argv){ srand(unsigned int(time(NULL))); //seed the random numbers once if(argc != 3){ //really minimul error checking cout << "Incorrect number of arguments." < maxGoal){ //check each thread to see if it hits goal race = false; cout << endl << "And the winner is : " << i << endl; threadList[i].winPrint(); for(int j = 0; j < numThreads; ++j){ //print loser status if(j != i){ threadList[j].lostPrint(); } } WaitForMultipleObjects(DWORD(numThreads),handles,true, 0); } } } return 0; }