спасибо!
процесс А
#include "stdafx.h"
#include "process.h"
#include <windows.h>
int main(void)
{
DWORD dwWaitResult;
STARTUPINFO si;
PROCESS_INFORMATION pi;
HANDLE hEvent1=CreateEvent (NULL, FALSE, FALSE,L"hEvent1");
HANDLE hEvent2=CreateEvent(NULL,FALSE,FALSE,L"hEvent2");
HANDLE hEvent3=CreateEvent(NULL,FALSE,FALSE,L"hEvent3");
ZeroMemory(&si, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
if (!CreateProcess
(L"C:\\B\\Debug\\B.exe", NULL, NULL, NULL, FALSE,CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi))
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
do
{
HANDLE events[]={hEvent1, hEvent2,hEvent3};
SetEvent(events[rand()&1]);
DWORD dwWaitResult = WaitForSingleObject(hEvent3, INFINITE);
}
while (dwWaitResult!=WAIT_OBJECT_0);
return 0;
}
процесс B
#include "stdafx.h"
#include <windows.h>
#include <iostream>
int main(int argc, char* argv[])
{
HANDLE hEvent1 = OpenEvent(NULL,FALSE,L"hEvent1");
HANDLE hEvent2 = OpenEvent(NULL,FALSE,L"hEvent2");
HANDLE hEvent3 = OpenEvent(NULL,FALSE,L"hEvent3");
int k=0;
while (k<100)
{
HANDLE events[]={hEvent1, hEvent2};
DWORD dwWaitResult = WaitForMultipleObjects(2, events, FALSE, 0);
if (dwWaitResult==WAIT_OBJECT_0)
{
std::cout<<"X";
}
if (dwWaitResult==WAIT_OBJECT_0+1)
{
std::cout<<"Y";
}
k++;
}
if (k==100)
{
SetEvent(hEvent3);
return 0;
}
}