Can anyone share some links or its own experience on the interprocess synchronization on windows. I run more instances of my program (each having 1 Thread) and want to synchronize them. I read bunch of functions related to it link, none seems to give an example on the interprocess communication (they all talk about the thread synchronization). So I want the process to wait until all the processes have reached the same line in the code.
Here is what I am having so far:;
interprocess_mtx = CreateMutex(NULL, FALSE, TEXT("mtx_name"));
if (interprocess_mtx == NULL) {
return (int)GetLastError();
}
if (WaitForSingleObject(interprocess_mtx, 10000) == WAIT_OBJECT_0) {
// here comes the code that needs to be executed synchronously
ReleaseMutex(interprocess_mtx);
}
if (CloseHandle(interprocess_mtx) == 0){
return (int)GetLastError();
}
Thanks
// Edited Solution: I run the first .exe file, wait for some small time, then run the rest. The first process creates a named mutex, locks it, waits for e.g. 5 seconds and releases it. The rest of the exe files (processes) create the same named mutex, then lock the mutex and release immediately. The critical code section is executed after the release.