Hi Crista: again on page 158. I was assuming that the DJ and Java program had the same behavior regarding notifications. If we would like this, could we change in the method manager for put: empty = false; to if (usedSlots==1) empty=false; Then the COOL code should only notify if a condition variable has actually changed. Does your implementation do this? Josh, does your implementation do it. -- Karl ================ From lopes@parc.xerox.com Wed Oct 29 19:00:05 1997 Sender: Cristina Lopes From: Cristina Lopes To: Karl Lieberherr Subject: Re: typos Karl Lieberherr writes: > on page 158: in Java: you check whether the buffer is empty after a put > and whether it is full after a take. Does not sound right. Karl, When I went back to chapter 5 to correct the bug, I realized that it is not a bug - it's correct. When you put an element, and just before you return, you check if the buffer _was_ empty. (Note that the test takes precedence over the increment) If the buffer _was_ empty, there may be threads suspended waiting to take an element, and that's why you notify. If the buffer _was_not_ empty, then no threads could possibly be suspended. Same for take(). -Crista ============ Hi Crista: I see; that makes sense. But then you should write, I think, if (usedSlots++ == 0) (NOT if (++usedSlots == 0)) so that for the test the old value of usedSlots is used, or better: if (usedSlots == 0) notifyAll(); usedSlots++; -- Karl From lopes@parc.xerox.com Thu Oct 30 21:03:30 1997 From: Cristina Lopes To: Karl Lieberherr Subject: Re: minimize notifies Karl Lieberherr writes: > Hi Crista: > > again on page 158. > > I was assuming that the DJ and Java program had the same behavior regarding > notifications. They have the same behavior, but not necessarily the same implementation. > If we would like this, could we change in the method manager for put: > > empty = false; > > to > > if (usedSlots==1) empty=false; > > Then the COOL code should only notify if a condition variable has actually > changed. Does your implementation do this? Yes - ideally notifications should be specific to condition variables. But that's a bit more complex to implement - although not impossible.