I have some code in process A that needs to wait until work completes in other processes that can be running simultaneously under multiple users.

I'm uncertain what is the appropriate synchronization mechanism. I naively thought a global named semaphore would be the answer but semaphores are signaled once anyone releases them, and I would want to wait until all clients release them, or a timeout occurs.

Question: Is there an appropriate synchronization mechanism for this scenario?

  • 1
    Which programming language? In C# you would use Task.WaitAll(), though I suppose that won't work if you're waiting on processes. For that, you would do this. See also this Google search. – Robert Harvey May 5 '17 at 0:18
  • I'm not waiting for the process to complete; I'm waiting for work within the process to complete. – Craig May 5 '17 at 1:13
  • 1
    No, you're waiting on processes to complete. How else are you going to get a signal from each process if you can't get a return value? – Robert Harvey May 5 '17 at 1:28
  • 2
    Plenty of ways - global named semaphores, global named events, named pipes, – Craig May 5 '17 at 2:02

I think a named pipe and waiting for confirmation messages from the n processes should work (i.e. the supervisor waits for n messages on the pipe). This would have the advantage of also allowing a complex result to be posted instead of just a notification, should this be required.


One possibility (as long as you don't have a huge number of tasks) is to have an array of Events, one for each task.

Each child process can set its associated Event when it finishes its task. The parent uses WaitForMultipleObjects (passing true for the bWaitAll parameter) to wait until they're all finished.

  • This is a solid idea but I don't know the number of tasks ahead of time so quantity is a concern. – Craig May 15 '17 at 0:22

Sounds like multi reader single writer pattern. I believe that you need a semaphore and a mutex (or two) to make this work correctly.

  • And they will need to be in the global namespace to handle multiple user's. – Mike May 13 '17 at 23:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.