John Keiser wrote:
> 
> On 21 Aug 2001 13:47:50 +0200, Dalibor Topic wrote:

> > public class WaitingPushbackInputStream extends PushbackInputStream {
> > [...]
> >     public int read() throws IOException {
> >       synchronized(this) {
> >           synchronized(in) {
> >               while(0 == available()) {
> >                   try {
> >                       wait();
> >                   }
> >                   catch (InterruptedException e) {
> >                       // ignore
> >                   }
> >               }
> >
> >               // something is available for reading,
> >               // and we've got both locks. this read
> >               // should not block at all.
> >               return super.read();
> >           }
> >       }
> >     }
> >
> >     public void unread(int oneByte) throws IOException {
> >       synchronized(this) {
> >           notifyAll();
> >           super.unread(oneByte);
> >       }
> >     }
> > }

> That's some nice code.  But how could super.unread() ever get called if
> read() is in its loop?  They're both synchronized on this.

AIUI, wait() causes all monitors to be temporarily released. So a call
to unread() will go through as soon as read() hits the line that says
wait().

But ICBVW...

Stuart.

_______________________________________________
Classpath mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/classpath

Reply via email to