OEP

166

Title

Output guards

Summary

Allow output guards in ALTs

Owner

Peter Welch <P.H.Welch@kent.ac.uk>

Status

Proposed

Date-Proposed

Some time in the early 80s

Last-Modified

2008-01-14

Keywords

language alt guards channels

For as long as occam's existed, programmers have wondered why ALT supports input guards but not output guards. Output guards are easy to implement (and CCSP already does so), but there's no language binding for them. The classic conceptual problem with output guards is demonstrated by the following code:

CHAN INT c, d:
PAR
  PRI ALT
    c ! A
      SKIP
    d ? x
      SKIP
  PRI ALT
    d ! B
      SKIP
    c ? y
      SKIP

Both c and d become ready at the same time, but the runtime must pick one of the two to fire, and therefore the PRI ALT ordering guarantee must be broken for one of the two PRI ALTs.

One fix for this is to prevent this situation from arising in the first place: we need to prevent a channel from being used for both an input and an output guard at the same time. This could be done by marking channels explicitly as input-altable or output-altable (more or less as JCSP does):

ALTABLE! CHAN INT c:
CHAN+ INT c:

or by carrying some extra information around in the usage checker.

Alternatively, we could weaken the PRI ALT ordering semantics. This may be a more attractive option, since the same ordering problem comes up with altable barriers:

BARRIER a, b:
PAR BARRIER a, b
  PRI ALT
    SYNC b
      SKIP
    SYNC a
      SKIP
  PRI ALT
    SYNC a
      SKIP
    SYNC b
      SKIP

OEP/166 (last edited 2008-01-14 13:11:09 by ats)