home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
High Voltage Shareware
/
high1.zip
/
high1
/
DIR4
/
V12N16.ZIP
/
SYNC.ZIP
/
SYNC2.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-26
|
893b
|
46 lines
/*---------------------------------------
SYNC2.C -- NT Synchronization Demo #2
(c) Charles Petzold, 1993
---------------------------------------*/
#include <windows.h>
#include <process.h>
#include <stdio.h>
CRITICAL_SECTION cs ;
int a [5] ;
void Thread (void * pParams)
{
int i, num = 0 ;
while (TRUE)
{
EnterCriticalSection (&cs) ;
for (i = 0 ; i < 5 ; i++)
a [i] = num ;
LeaveCriticalSection (&cs) ;
num++ ;
}
}
int main (void)
{
InitializeCriticalSection (&cs) ;
_beginthread (Thread, 0, NULL) ;
while (TRUE)
{
EnterCriticalSection (&cs) ;
printf ("%d %d %d %d %d\n", a[0], a[1], a[2], a[3], a[4]) ;
LeaveCriticalSection (&cs) ;
}
return 0 ;
}