1

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
1

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.

1

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
1

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

protected by gnat May 14 '17 at 4:57

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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