[an error occurred while processing this directive]
|
#include "stdafx.h"
#include
CRITICAL_SECTION cs;
//
struct {
int a;
int b;
} common_struct;
//DWORD WINAPI MyThread (LPVOID *unused)
{
for (;;)
{
EnterCriticalSection(&cs);
common_struct.a++, common_struct.b++;
LeaveCriticalSection(&cs);
Sleep(0);
}
return 0;
}
//
int _tmain(int argc, _TCHAR* argv[])
{
DWORD dwID = 0;
InitializeCriticalSection(&cs);
HANDLE hMyThr = CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE)MyThread, NULL, CREATE_SUSPENDED, &dwID);
ResumeThread(hMyThr);
for (;;)
{
EnterCriticalSection(&cs);
printf ("a = %d, b = %d\n", common_struct.a, common_struct.b);
LeaveCriticalSection(&cs);
Sleep(0);
}
return 0;
}
E-mail: info@telesys.ru