|
《Windows游戏编程大师技巧》(第二版)第11章(29) break; } // end for index // decrement number of active threads if (active_threads > 0) active_threads--; // just return the data sent to the thread function return((DWORD)data); } // end Printer_Thread // MAIN ////////////////////////////////////////////////////// void main(void) { HANDLE thread_handle[MAX_THREADS]; // this holds the // handles to the threads DWORD thread_id[MAX_THREADS]; // this holds the ids of the threads // start with a blank line printf("\nStarting Threads...\n"); // create the thread, IRL we would check for errors for (int index=0; index < MAX_THREADS; index++) { thread_handle[index] = CreateThread(NULL, // default security 0, // default stack Printer_Thread, // use this thread function (LPVOID)index, // user data sent to thread 0, // creation flags, 0=start now. &thread_id[index]);// send id back in this var // increment number of active threads active_threads++; } // end for index // now enter into printing loop, make sure this
|