Re: the wait() and pulse() of monitor
From: pt (flybird_fz_at_21cn.com.AntiSpam)
Date: 03/09/04
- Next message: Matt: "Re: Obfuscation and Salamander"
- Previous message: S. B_at_RTHES: "Re: Obfuscation and Salamander"
- In reply to: Jon Skeet [C# MVP]: "Re: the wait() and pulse() of monitor"
- Next in thread: Jon Skeet [C# MVP]: "Re: the wait() and pulse() of monitor"
- Reply: Jon Skeet [C# MVP]: "Re: the wait() and pulse() of monitor"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 9 Mar 2004 17:03:57 +0800
"Jon Skeet [C# MVP]" <skeet@pobox.com> ????
news:MPG.1ab78b802f81047298a37b@msnews.microsoft.com...
...
> 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.
> The lock isn't held by anyone for long.
>
> > So there is three state for the worker
> >
> > wait--pulsed(don't get the lock and still can do nothing)--get lock and
work
> >
> > I just wonder why introduced the middle state--pulsed? I still think
> > in this case it is not necessary.
>
> 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.
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.
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.
regards,
PanTao
- Next message: Matt: "Re: Obfuscation and Salamander"
- Previous message: S. B_at_RTHES: "Re: Obfuscation and Salamander"
- In reply to: Jon Skeet [C# MVP]: "Re: the wait() and pulse() of monitor"
- Next in thread: Jon Skeet [C# MVP]: "Re: the wait() and pulse() of monitor"
- Reply: Jon Skeet [C# MVP]: "Re: the wait() and pulse() of monitor"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|