[Cst-1b] CST1-b Question: Java 98/4/3
M.Y.W.Y.B.
mywyb2@hermes.cam.ac.uk
Tue, 02 May 2000 23:19:17 +0100
--On Mittwoch, 3. Mai 2000, 22:46 +0100 "Martin Harper" <mcnh2@cam.ac.uk>
wrote:
> Surely you do exactly the same as synchronization, but instead of writing
-
>
> synchronized {
> // protected code
> }
>
> you write -
> int tick = m.turn();
> s.queue(tick);
> // protected code
> s.next()
> (where m & s are a machine and a scheduler for the given object...)
I think it's not as simple as that. Don't forget it's a *bounded* buffer
(bound=1 element). For that we need two methods: put(int value) and get().
But we can only put if the buffer is empty and get if the buffer is full,
otherwise the thread must be suspended and woken up later, so we need
methods for IPC. Usually you would use wait()/notifyAll() but here we are
not supposed to.