Click to See Complete Forum and Search --> : synchronizing waiting and signaling of event


mgore
July 9th, 2007, 06:29 AM
hi,

I have two threads, the first one wait on an event and the second signals the event,

I want to ensure that while the first thread tries to wait for an event the second thread should not signal the event..

how do I do this?

Mihir

miteshpandey
July 9th, 2007, 07:13 AM
hi,

I have two threads, the first one wait on an event and the second signals the event,

I want to ensure that while the first thread tries to wait for an event the second thread should not signal the event..

how do I do this?

Mihir

Your first thread is waiting and the second thread is signalling.

To achieve what you want one should let the signalling thread to wait and the waiting thread to signal using another event. However this may lead to a deadlock

I think there is a design flaw somewhere but still your question is a little vague. Your code should be such that it doesn't depend on whether the first thread goes to wait state first or the second thread signals the event first. Can you explain a bit more what you want to achieve?

Arjay
July 9th, 2007, 12:45 PM
In terms of the design, are both threads accessing some common resource?

exterminator
July 15th, 2007, 01:17 AM
To achieve what you want one should let the signalling thread to wait and the waiting thread to signal using another event. However this may lead to a deadlockI don't think this should create a deadlock - but it leaves the original problem as it is. Now again, the signalling thread can signal before the second starts to wait.

Using a shared thread safe flag, I think this can be solved. The waiting thread sets the "signal" flag to true as soon as it is ready to listen and the singalling one checks this variable in a loop waiting for a predefined interval at each loop iteration and breaks out of it as soon as it gets the signal flag set to true. Does this approach make sense?