I have two C++ processes (A and B), executing under Windows, where one launches the other. I would like to effectively single-thread their execution. For example:
- Start process A
- A creates B
- A suspends
- B executes some fixed set of operations
- B suspends and A is resumed
- A executes some fixed set of operations
- A suspends and B is resumed
- (Repeat 4 – 7)
Which Windows synchronization and IPC services would be best to implement this type of behavior?
Events would work in this case:
Just be sure you have error handling so each process can resume and do whatever is necessary if the other one hangs or terminates unexpectedly. Timeouts can handle the hang situation, and waiting on the other process’s handle (using WaitForMultipleObjects() along with both the process and event handle) can determine if/when the other process terminates.