#include "stdafx.h"
#include <wtypes.h>
int g_n;
DWORD WINAPI ThreadPro1(LPVOID lpThreadParameter)
{
for (int i = 0; i < 100000;i++)
{
InterlockedIncrement((ULONG *)&g_n);
}
return 0;
}
DWORD WINAPI ThreadPro2(LPVOID lpThreadParameter)
{
for (int i = 0; i < 100000; i++)
{
InterlockedIncrement((ULONG *)&g_n);
}
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
HANDLE hThread1 = 0, hThread2 = 0;
hThread1 = CreateThread(NULL, NULL, ThreadPro1, NULL, NULL, NULL);
hThread2 = CreateThread(NULL, NULL, ThreadPro2, NULL, NULL, NULL);
WaitForSingleObject(hThread1, INFINITE);
WaitForSingleObject(hThread2, INFINITE);
printf("%d\n", g_n);
system("pause");
return 0;
}