I am trying to use an event object in a win32 environment to synchronize two processes. The following is a simplified code of two programs.
int main()
{
HANDLE h = CreateEvent(NULL, FALSE, FALSE, TEXT("Hello"));
WaitForSingleObject(h, INFINITE);
}
int main()
{
HANDLE h = OpenEvent(EVENT_MODIFY_STATE, FALSE, TEXT("Hello"));
SetEvent(h);
}
This is pretty simple and works well when two processes start independently. However, this does not work when process 1 starts process 2 as a child process (which is commented out in the code above) - the SetEvent call fails. What is the reason and solution to this problem?
source
share