next up previous contents
Next: Limitations of the prototype Up: Communication infra-structure: Channels Previous: Stream interfaces   Contents

Non-deterministic communications

A functionality similar to the ``merge'' in Fortran-M is provided through the ``merge pool'' class, Merge. The public interface is

  public class Merge {
    public Merge() ;

    public void add(Port P) ;
    public void rem(Port P) ;

    public Port select() ;
  }
When initially created, a merge pool is empty. Channel ends are added to or removed from the pool by passing the associated ports to the add and rem members.

The only other operation on a merge pool is select. This returns a port from the pool which presently has input data ready. If no port has a message ready when the call is executed select blocks until a message arrives.

Merge pools enable non-deterministic patterns of communication.

Example usage

  Merge pool = new Merge() ;

  for(int i = 0 ; i < NNODES ; i++) {

    // ... create a slave process which returns data on port `U'

    pool.add(U) ;
  }

  while(nodesActive) {
    Port V = pool.select() ;

    DataInputStream fromNode = new DataInputStream(new PortInputStream(V)) ;

    // ... read data from from slave
  }
Note that the port returned by select remains in the pool. Ports can only be removed from the pool by using rem.

In the present implementation a channel end can belong to at most one merge pool at any given time.



Bryan Carpenter 2002-07-12