Link to home
Start Free TrialLog in
Avatar of HarishMinu
HarishMinu

asked on

Synchronization between instances of same processes using CreateEvent

Hello experts

I have a problem when synchronizing the same instances of a process. My application will call from other jobs simultaneously , it instantiate the multiple instances of the application.

 I want to create a event in the application and signal it  after completion of one instance I will un-signal it,  other instances should instances should wait until first completes.

created sample code. but it is in infinite loop.

            HANDLE  hEvent1 = CreateEvent ( NULL , true , false , L"MyEvent" );
            hEvent = OpenEvent ( EVENT_ALL_ACCESS , false, L"MyEvent" );
            if(GetLastError () == ERROR_ALREADY_EXISTS)
            {
                  while (WaitForSingleObject(hEvent,INFINITE)==WAIT_OBJECT_0)
                  {
                        Sleep(0);
                  }
                  SetEvent (hEvent);
            }
            else
                  SetEvent (hEvent );




//in the ending of application.
ResetEvent (hEvent);


Please advise
Thanks in advance
ASKER CERTIFIED SOLUTION
Avatar of sarabande
sarabande
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial