#include #include #include #include #include #include #include #include #include #include /* ** This is the function that is going to run for each thread */ DWORD WINAPI ThreadFunction(void *ThreadNumber) { int OurThreadNumber; int i; OurThreadNumber = *(int*) ThreadNumber; /* ** Sleep a little so that the main line can get all of the threads running */ Sleep(200); /* ** Seed the random number for the sleep */ srand( (unsigned)time( NULL ) ); /* ** Count to 100 */ for(i=0;i<100;i++) { printf("Thread number %d loop number %d\n",OurThreadNumber,i); /* ** Sleep a random amount of time */ Sleep(rand()%200); } return(0); } /* ** This is the main function */ void main(void) { int i; HANDLE hThread=NULL; for(i=0;i<20;i++) { /* ** Start the threads */ hThread = CreateThread(NULL, 0, &ThreadFunction, (LPVOID)&i, 0, NULL); Sleep(8); } /* ** Let all of the threads finish before we finish the program */ Sleep(20000); }