By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,584 Members | 1,065 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,584 IT Pros & Developers. It's quick & easy.

producer/consumer don't understand

P: n/a
class Buffer {
const int size = 4;
int n = 0;

public void Put(char ch)
{
lock(this)
{
while (n == size)
Monitor.Wait(this);

n++;

Monitor.Pulse(this);
}
}

public void Get(char ch)
{
lock(this)
{
while (n == 0)
Monitor.Wait(this);

n--;

Monitor.Pulse(this);
}
}
}

I found the above program on the web. It shows how a producer/consumer works
with the Monitor class. It says if the producer is faster than the consumer
then I can expect the following result:

Put
Put
Put
Put
Get
Put
Get
....

and if the consumer is faster:

Put
Get
Put
Get
....
My question is this: I don't understand the result when the producer is
faster. How can you have too many Puts after each other?
Nov 16 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.