home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR4 / V12N16.ZIP / SYNC.ZIP / SYNC3.C < prev    next >
C/C++ Source or Header  |  1993-06-26  |  910b  |  46 lines

  1. /*---------------------------------------
  2.    SYNC3.C -- NT Synchronization Demo #3
  3.           (c) Charles Petzold, 1993
  4.   ---------------------------------------*/
  5.  
  6. #include <windows.h>
  7. #include <process.h>
  8. #include <stdio.h>
  9.  
  10. HANDLE hMutex ;
  11.  
  12. int a [5] ;
  13.  
  14. void Thread (void * pParams)
  15.      {
  16.      int i, num = 0 ;
  17.  
  18.      while (TRUE)
  19.           {
  20.           WaitForSingleObject (hMutex, INFINITE) ;
  21.  
  22.           for (i = 0 ; i < 5 ; i++)
  23.                a [i] = num ;
  24.  
  25.           ReleaseMutex (hMutex) ;
  26.  
  27.           num++ ;
  28.           }
  29.      }
  30.  
  31. int main (void)
  32.      {
  33.      hMutex = CreateMutex (NULL, FALSE, NULL) ;
  34.  
  35.      _beginthread (Thread, 0, NULL) ;
  36.  
  37.      while (TRUE)
  38.           {
  39.           WaitForSingleObject (hMutex, INFINITE) ;
  40.           printf ("%d %d %d %d %d\n", a[0], a[1], a[2], a[3], a[4]) ;
  41.           ReleaseMutex (hMutex) ;
  42.           }
  43.  
  44.      return 0 ;
  45.      }
  46.