#include <stdio.h>
#include <Windows.h>
#include <iostream>
using namespace std;
int t1=10;
int t2=10;
int t3=10;
HANDLE m1;
HANDLE m2;
HANDLE m3;
DWORD WINAPI Thread1Proc(LPVOID argv)
{
while(1)
{
WaitForSingleObject(m1,INFINITE);
if(t1>0)
cout << "Thread1Func:"<<t1--<<"\n";
ResetEvent(m1);
SetEvent(m2);
}
return 0;
}
DWORD WINAPI Thread2Proc(LPVOID argv)
{
while(2)
{
WaitForSingleObject(m2,INFINITE);
if(t2>0)
cout << "Thread2Func:"<<t2--<<"\n";
ResetEvent(m2);
SetEvent(m3);
}
return 0;
}
DWORD WINAPI Thread3Proc(LPVOID argv)
{
while(3)
{
WaitForSingleObject(m3,INFINITE);
if(t3>0)
cout << "Thread3Func:"<<t3--<<"\n";
ResetEvent(m3);
SetEvent(m1);
}
return 0;
}
int main()
{
HANDLE Thread1;
HANDLE Thread2;
HANDLE Thread3;
m1=CreateEvent(NULL,FALSE,FALSE,NULL);
m2=CreateEvent(NULL,FALSE,FALSE,NULL);
m3=CreateEvent(NULL,FALSE,FALSE,NULL);
Thread1 = CreateThread(0,0,Thread1Proc,0,0,0);
Thread2 = CreateThread(0,0,Thread2Proc,0,0,0);
Thread3 = CreateThread(0,0,Thread3Proc,0,0,0);
cout << "main thread\n";
SetEvent(m1);
Sleep(100);
system("pause");
return 0;
}
#include <Windows.h>
#include <iostream>
using namespace std;
int t1=10;
int t2=10;
int t3=10;
HANDLE m1;
HANDLE m2;
HANDLE m3;
DWORD WINAPI Thread1Proc(LPVOID argv)
{
while(1)
{
WaitForSingleObject(m1,INFINITE);
if(t1>0)
cout << "Thread1Func:"<<t1--<<"\n";
ResetEvent(m1);
SetEvent(m2);
}
return 0;
}
DWORD WINAPI Thread2Proc(LPVOID argv)
{
while(2)
{
WaitForSingleObject(m2,INFINITE);
if(t2>0)
cout << "Thread2Func:"<<t2--<<"\n";
ResetEvent(m2);
SetEvent(m3);
}
return 0;
}
DWORD WINAPI Thread3Proc(LPVOID argv)
{
while(3)
{
WaitForSingleObject(m3,INFINITE);
if(t3>0)
cout << "Thread3Func:"<<t3--<<"\n";
ResetEvent(m3);
SetEvent(m1);
}
return 0;
}
int main()
{
HANDLE Thread1;
HANDLE Thread2;
HANDLE Thread3;
m1=CreateEvent(NULL,FALSE,FALSE,NULL);
m2=CreateEvent(NULL,FALSE,FALSE,NULL);
m3=CreateEvent(NULL,FALSE,FALSE,NULL);
Thread1 = CreateThread(0,0,Thread1Proc,0,0,0);
Thread2 = CreateThread(0,0,Thread2Proc,0,0,0);
Thread3 = CreateThread(0,0,Thread3Proc,0,0,0);
cout << "main thread\n";
SetEvent(m1);
Sleep(100);
system("pause");
return 0;
}