Re: the wait() and pulse() of monitor
From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 03/09/04
- Next message: Jon Skeet [C# MVP]: "Re: Obfuscation and Salamander"
- Previous message: Warut: "RE: InvalidOperationException error on GetProcessesByName"
- In reply to: pt: "Re: the wait() and pulse() of monitor"
- Next in thread: pt: "Re: the wait() and pulse() of monitor"
- Reply: pt: "Re: the wait() and pulse() of monitor"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 9 Mar 2004 10:08:13 -0000
pt <flybird_fz@21cn.com.AntiSpam> wrote:
> > No, the producer doesn't use wait itself at all. The sequence is:
> >
> > Consumer: Producer:
> > Enter lock
> > Wait (exits lock)
> > Enter lock
> > Pulse
> > Exit lock
> > Regain lock
> > Exit lock
>
> It is just for one time operation. If producer produces more , then
> there will a loop in the block and in the loop pulse and wait will
> be used.
No, the producer would just pulse multiple times. Why would the
producer wait? The idea of this is that the producer is just using
"fire and forget" semantics.
> > I think you're missing something, but it's hard to say what it is, I'm
> > afraid.
>
> the explain for pulse is so in msdn:
> Sends a signal to one or more waiting threads. The signal notifies a waiting
> thread that the state of the locked object has changed, and the owner of the
> lock is ready to release the lock. The waiting thread is placed in the
> object's ready queue so that it might eventually receive the lock for the
> object.Once the thread has the lock, it can check the new state of the
> object to see if the required state has been reached.
>
> I think once wait() is called, the thread fall into a state wait and can't
> join the competion for the lock unless being pulsed first.
Yes. (Assuming a timeout isn't specified.)
> so totally I think there are three state:
>
> gain lock, wait and have not been pulsed, waitlock(means just waiting the
> lock,while first enter() or have been pulsed).and pulse() can let thread
> change from wait to waitlock.
Um, I think so.
> I think the wait state introduce more control function, but I would like to
> see which case it should be used. I think it will used while there is more
> threads and the control is complex, but I can't imagine the detail case.
I've shown you a case where it's used - the classic producer/consumer
situation, with a queue of jobs. Please explain how you would tackle
that without wait/pulse (or any similar but equivalent mechanism).
-- Jon Skeet - <skeet@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
- Next message: Jon Skeet [C# MVP]: "Re: Obfuscation and Salamander"
- Previous message: Warut: "RE: InvalidOperationException error on GetProcessesByName"
- In reply to: pt: "Re: the wait() and pulse() of monitor"
- Next in thread: pt: "Re: the wait() and pulse() of monitor"
- Reply: pt: "Re: the wait() and pulse() of monitor"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|