Re: the wait() and pulse() of monitor
From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 03/11/04
- Next message: David Pizzi: "Which reporting tool"
- Previous message: Jon Skeet [C# MVP]: "Re: System.Type.GetType problem"
- In reply to: pt: "Re: the wait() and pulse() of monitor"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 11 Mar 2004 08:05:03 -0000
pt <flybird_fz@21cn.com.AntiSpam> wrote:
> I just think in the producer/consumer case, the complex corporation
> that pulse() and wait() is not used, since in the case, the state(
> waited but haved not been pulsed) for consumer has no special effect,
> and the state is no necessary in the case.
How exactly do you make the consumer wait until the producer has
produced something and reliably then consume it?
> and the producer has
> to use two step pulse() and exit() or wait to do the work, and
> with other machanism such as samaphore, just one step does the work.
No, the producer can't hold the lock the whole time and just release it
to effectively pulse the consumer, for two reasons:
1) There may well be more than one producer
2) There's no guarantee that *as soon as* the producer releases the
lock, the consumer will get it. If the producer is then going to
acquire the lock again, that may happen before the consumer acquires
it.
Nothing should hold locks for long periods of time, in my view, but I
*think* that's what you're proposing.
-- Jon Skeet - <skeet@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
- Next message: David Pizzi: "Which reporting tool"
- Previous message: Jon Skeet [C# MVP]: "Re: System.Type.GetType problem"
- In reply to: pt: "Re: the wait() and pulse() of monitor"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|