// The event object also belongs to the kernel object and contains a usage count, // A boolean value that indicates whether the event is an automatically reset event or a manually reset event, // Another Boolean value used to indicate whether the event is in the notified or not notified status. // There are two different types of event objects. One is a manual reset event, and the other is an automatic reset event. // When a manually reset event is notified, all threads waiting for the event change to schedulable threads. // When an automatically reset event is notified, only one thread in the thread waiting for the event changes to a schedulable thread. # Include <Windows. h> # Include <Iostream>Using Namespace STD; DWORD winapi fun1proc (lpvoid lpparameter); DWORD winapi fun2proc (lpvoid lpparameter ); Int Tickets = 100 ; Handle g_hevent; Void Main () {handle hthread1; handle hthread2; g_hevent = Createevent (null, false, true, null ); // Set to auto reset // Setevent (g_hevent ); Hthread1 = createthread (null,0 , Fun1proc, null, 0 , Null); hthread2 = Createthread (null, 0 , Fun2proc, null, 0 , Null); closehandle (hthread1); closehandle (hthread2); sleep ( 4000 );} DWORD winapi fun1proc (lpvoid lpparameter ){ While (True) {waitforsingleobject (g_hevent, infinite ); If (Tickets> 0 ) {Sleep ( 1 ); Cout < " Thread1 javasticket: " <Tickets -- < Endl ;} Else Break ; Setevent (g_hevent );} Return 0 ;} DWORD winapi fun2proc (lpvoid lpparameter ){ While (True) {waitforsingleobject (g_hevent, infinite ); If (Tickets> 0 ) {Sleep ( 1 ); Cout < " Thread2 javasticket: " <Tickets -- < Endl ;} Else Break ; Setevent (g_hevent );} Return 0 ;}