|
《Windows游戏编程大师技巧》(第二版)第11章(28) // DEMO11_7.CPP - An example of global message passing to control // termination of threads. // INCLUDES /////////////////////////////////////////////////////// #define WIN32_LEAN_AND_MEAN // make sure certain headers // are included correctly #include <windows.h> // include the standard windows stuff #include <windowsx.h> // include the 32 bit stuff #include <conio.h> #include <stdlib.h> #include <stdarg.h> #include <stdio.h> #include <math.h> #include <io.h> #include <fcntl.h> // DEFINES ////////////////////////////////////////////////////// #define MAX_THREADS 3 // PROTOTYPES ////////////////////////////////////////////////// DWORD WINAPI Printer_Thread(LPVOID data); // GLOBALS ///////////////////////////////////////////////////// int terminate_threads = 0; // global message flag to terminate int active_threads = 0; // number of active threads // FUNCTIONS //////////////////////////////////////////////// DWORD WINAPI Printer_Thread(LPVOID data) { // this thread function simply prints out data until it is told to terminate for(;;) { printf("%d ",(int)data+1); // output a single character Sleep(100); // sleep a little to slow things down // test for termination message if (terminate_threads)
|