[Cst-1b] CST1-b Question: Java 98/4/3 (solution)

Phebe Mann pm258@hermes.cam.ac.uk
Wed, 3 May 2000 17:02:12 +0100 (BST)


---------- Forwarded message ----------
Date: Wed, 03 May 2000 13:41:59 +0100
From: M.Y.W.Y.B. <mywyb2@hermes.cam.ac.uk>
To: cst-1b@srcf.ucam.org
Subject: Re: [Cst-1b] CST1-b Question: Java 98/4/3 (solution)

--On Donnerstag, 4. Mai 2000, 00:47 +0100 "Martin Harper" <mcnh2@cam.ac.uk>
wrote: 
[...]
> This is something of a clumsy answer, however - and I'm not sure if it
would
> lose marks for that. Something better can be done.
[...]

Yes, I think that's the right way to go. I suggest just two subtle
corrections:

[...]
>     int read() {
>         int readernum = rm.turn();
>         rs.queue(readernum);
>         int temp = val;
>         rs.next();
>         return temp;
>     }

Corrected version of read():

     int read() {
         int readernum = rm.turn() + 1;  // CHANGED
         rs.queue(readernum);
         int temp = val;
         ws.next();                      // CHANGED
         return temp;
     }

The second change is obvious. The first one is necessary because in the
original version you could 
1) read before there was a value in the buffer
2) store something and read twice
Now the first reader ticket is 1 and not 0 and everything should be fine.


Moritz, quite a clever idea, never thought about this, Thanks

Thanks!

Moritz


_______________________________________________
CST-1B mailing list
CST-1B@srcf.ucam.org
http://www.srcf.ucam.org/mailman/listinfo/cst-1b