#include <cstdlib>
#include <iostream>
#include <windows.h>
#include <process.h>
HANDLE hMutex;
int sum = 0;
void plus(void *)
{
WaitForSingleObject(hMutex, INFINITE);
for (int i=0; i<100000; i++)
{
++sum;
}
ReleaseMutex(hMutex);
}
int main(int argc, char *argv[])
{
hMutex = CreateMutex(NULL, FALSE, NULL);
_beginthread(&plus, 0, NULL);
_beginthread(&plus, 0, NULL);
_beginthread(&plus, 0, NULL);
Sleep(5000);
printf("%d\n", sum);
system("PAUSE");
return EXIT_SUCCESS;
}