int xppp;
public ref class A
{
public:
void fun(void *)
{ while(xppp<99)
{
WaitForSingleObject(hPrintMutex,INFINITE);
xppp+=2;
cout<<xppp<<endl;
ReleaseMutex(hPrintMutex);
Sleep(10);
}
}
};
//Similarly
public ref class B{};
public ref class C{};
int main()
{
x=0;
hPrintMutex=CreateMutex(NULL,false,NULL);
B M2;
HANDLE hThread1=(HANDLE)_beginthread(B::fun,0,&M2);
A M1;
HANDLE hThread2=(HANDLE)_beginthread(A::fun,0,&M1);
C M3;
HANDLE hThread3=(HANDLE)_beginthread(C::fun,0,&M3);
WaitForSingleObject(hThread1,INFINITE);
WaitForSingleObject(hThread2,INFINITE);
WaitForSingleObject(hThread3,INFINITE);
return 0;
}
/* I also tried...
But unable to use the "WaitForSingleObject" which will synchronize
A^ M1=gcnew A();
Thread^ MainThread1 = gcnew Thread(gcnew ThreadStart(M1,&A::fun));
MainThread1->Start();
MainThread1->Join(); */