Class CHAN_OF_INT

Class CHAN_OF_INT

java.lang.Object
   |
   +----CHAN_OF_INT

class CHAN_OF_INT
extends Object
Channel extends an occam CHAN OF INT for multiple readers and writers. There is full synchronisation between a reading and writing thread. Any thread may read or write on this channel. Readers and writers are queued separately. A reader only completes when it gets to the front of its queue and finds a writer. A writer only completes when it gets to the front of its queue and finds a reader.

There is no logical buffering of data in the channel however each int is actually copied three times with this implementation.

Version:
$Revision: 1.1 $
Author:
Peter Welch, P.H.Welch@ukc.ac.uk, Dave Beckett, D.J.Beckett@ukc.ac.uk

Method Index

o is_empty()
is_empty method: determine whether a thread is waiting at the other end of the channel.
o read()
read method: read an int from the channel.
o write(int)
write method: write an int to the channel.

Methods

o read
  public int read() throws InterruptedException
read method: read an int from the channel. This method blocks until a corresponding thread calls the write method, at which point a rendezvous is formed and the data is passed.
Returns:
the object sent from the writing thread.
Throws: InterruptedException
Occurs if the wait methods are interrupted.
o write
  public void write(int n) throws InterruptedException
write method: write an int to the channel. This method blocks until a corresponding thread calls the read method, at which point a rendezvous is formed and the data is passed.
Parameters:
n - the int to be sent to the reading thread.
Throws: InterruptedException
Occurs if the wait methods are interrupted.
o is_empty
  public boolean is_empty()
is_empty method: determine whether a thread is waiting at the other end of the channel. This can be used either at the writing or the reading end of the channel.
Returns:
true iff no thread is waiting at the other end.