Process synchronisation

G

Guest

Hi,

I have several processes P1...Pn and every process is running the thread T1.

The proces P1 signales the named event E. I want that when the event E is
signaled, every thread T1 in processes P1..Pn will wake up and invoke a
delegate. Than this thread should wait for the next time, when event E will
be signaled by P1 again, and invoke delegate again.

If the event will be of type AutoReset, than only one thread will wake up
and after that the event will Reset. Thats bad, as other threads will not
wake up and will not invoke a delegate.

If the event will be of type Manual, than all threads T1 will wake up, but
every thread will run in a loop as the event will be still signaled.

My question is: How to wake up all threads, let them execute only once, and
than wait for the next signaled event?

Thanks for help,

Lubomir
 
N

Nicholas Paldino [.NET/C# MVP]

Lubomir,

I think that in this case, remoting, or WCF might be a good option.
This way, when you need to trigger actions in other processes, you can just
make calls into them, and know when they are all complete, as well.

This is the best solution, IMO, because if you are going to use
threading primitives, you will need multiple ones in order to synchronize
operations between all the processes, and this can be tricky to get right.

If you really need to use threading primitives, I would suggest using a
Semaphore to trigger the other processes (you can have a system wide one).
However, you will have to use an AutoResetEvent that is triggered by the
other processes to indicate to the main process that their work is done.
The main process would have to wait on as many AutoResetEvent instances as
there are other processes that it is waiting for.

Hope this helps.
 
G

Guest

Nicholas,

Thanks for help.

Lubomir



Nicholas Paldino said:
Lubomir,

I think that in this case, remoting, or WCF might be a good option.
This way, when you need to trigger actions in other processes, you can just
make calls into them, and know when they are all complete, as well.

This is the best solution, IMO, because if you are going to use
threading primitives, you will need multiple ones in order to synchronize
operations between all the processes, and this can be tricky to get right.

If you really need to use threading primitives, I would suggest using a
Semaphore to trigger the other processes (you can have a system wide one).
However, you will have to use an AutoResetEvent that is triggered by the
other processes to indicate to the main process that their work is done.
The main process would have to wait on as many AutoResetEvent instances as
there are other processes that it is waiting for.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


Lubomir said:
Hi,

I have several processes P1...Pn and every process is running the thread
T1.

The proces P1 signales the named event E. I want that when the event E is
signaled, every thread T1 in processes P1..Pn will wake up and invoke a
delegate. Than this thread should wait for the next time, when event E
will
be signaled by P1 again, and invoke delegate again.

If the event will be of type AutoReset, than only one thread will wake up
and after that the event will Reset. Thats bad, as other threads will not
wake up and will not invoke a delegate.

If the event will be of type Manual, than all threads T1 will wake up, but
every thread will run in a loop as the event will be still signaled.

My question is: How to wake up all threads, let them execute only once,
and
than wait for the next signaled event?

Thanks for help,

Lubomir
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top