大家好,又见面了,我是你们的朋友全栈君。
#define _AFXDLL
#include <afxmt.h>
#include <iostream>
using namespace std;
CCriticalSection critical;
int tick=0;
DWORD WINAPI Func1(LPVOID lpParam);
DWORD __stdcall Func1(LPVOID lpParam)
{
critical.Lock();
tick += 10;
cout << "Func1 TICK NOW IS : " << tick << endl;
critical.Unlock();
return 0;
}
DWORD WINAPI Func2(LPVOID lpParam);
DWORD __stdcall Func2(LPVOID lpParam)
{
critical.Lock();
tick += 10;
cout << "Func2 TICK NOW IS : " << tick << endl;
critical.Unlock();
return 0;
}
int main()
{
HANDLE t1 = CreateThread(NULL, 0, Func1, NULL, 0, NULL);
HANDLE t2 = CreateThread(NULL, 0, Func2, NULL, 0, NULL);
while (true)
{
}
CloseHandle(t1);
CloseHandle(t2);
return 0;
}
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/162057.html原文链接:https://javaforall.cn