0

I have 2 processes that i'd like to synchronize:

The first process (client) launches another process (a server app that starts some WCF services), and waits for it to reach a certain state.

I'd like the client process to start the server, and block until all services were launched.

To do this, the server initializes a Mutex object and uses it for signalling the client that it's done.

The problem with this approach is that the client doesn't know when the mutex has actually finished setting up the mutex and when to starting waiting on it.

Is there any formal algorithm/protocol (leave programming languages aside at the moment) for coordinating this kind of task?

lysergic-acid
  • 19,570
  • 21
  • 109
  • 218
  • 1
    It sounds like you need a cross-process event rather than a mutex. You just want to wait until the server signals that it's done. See this answer for more details on creating the event such that it can be shared across processes: http://stackoverflow.com/questions/2590334/creating-a-cross-process-eventwaithandle – RogerN Apr 17 '13 at 18:18

1 Answers1

0

The solution is to setup a semaphore in the client directly, before starting the server, and use the same mechanism as initially planned to let the other process know which synchronization object it must use.

In pseudo code, the basic outline would be something like this:

client:

create semaphore with initial count at 0;
spawn server;
wait on semaphore;

server:

process jobs;
release semaphore;

For either process, the problem is resolved: because the semaphore is set to 0, the wait done by the client will block, until the server releases it.

Msdn documentation:

didierc
  • 14,572
  • 3
  • 32
  • 52
  • So: client creates mutex, starts server. The server acquires mutex, how does the client know when the server acquired it? (to know it should start waiting for it itself?) – lysergic-acid Apr 17 '13 at 17:03
  • Your example is missing the fact that the server needs to acquire the mutex. And now it's a race condition between it and the client. – lysergic-acid Apr 17 '13 at 19:31
  • just fixed it. On unix systems I would have used a semaphore, and I realized that the device exists as well here, so you have it. – didierc Apr 17 '13 at 19:39