1#include"iostream"2#include"windows.h"3#include"CString"4 using namespacestd;5 6HANDLE g_hsemthreads=Invalid_handle_value;7 8 StaticDWORD WINAPI ThreadProc (lpvoid lpparam) {9LONG npausems=reinterpret_cast<long>(Lpparam);Ten Sleep (npausems); One A if(g_hsemthreads!=Invalid_handle_value) { -LONG NPREVCT (0); - the if(ReleaseSemaphore ( - G_hsemthreads, - 1, -&NPREVCT + )){ -printf"%d msec thread ended, slots left:%d\n", npausems,nprevct+1); + } A } at - return(0); - } - - - in voidMain () { -g_hsemthreads=CreateSemaphore ( to NULL, + 5, - 5, the NULL * ); $ for(intNtotal= -;ntotal>0; ntotal-=2){Panax Notoginseng WaitForSingleObject (g_hsemthreads,infinite); -LONG npausems=ntotal*5; the +HANDLE hthread=CreateThread ( A NULL, the 0, + ThreadProc, -Reinterpret_cast<lpvoid>(Npausems), $ 0, $ NULL - ); - theprintf"In the %d msec a thread is creates \ n", npausems); - CloseHandle (hthread);WuyiHthread=Invalid_handle_value; the } - Wu CloseHandle (g_hsemthreads); -g_hsemthreads=Invalid_handle_value; About GetChar (); $}