OEP

116

Title

Anonymous channel types

Summary

Provide SHARED channels by rewriting to channel types.

Owner

Fred Barnes <F.R.M.Barnes@kent.ac.uk>

Status

Accepted

Date-Accepted

2002-09-03

Keywords

language shared channels channel-types

Anonymous channel-types provide a convenience. Quite often, we want a mobile channel-end of only one channel. The usual way would be to declare a mobile channel-type with a single channel, and use that. For example:

CHAN TYPE THING
  MOBILE RECORD
    CHAN INT c?:
:

THING? svr:
SHARED THING! cli:
SEQ
  svr, cli := MOBILE THING
  PAR
    SEQ i = 0 FOR 2
      INT x:
      svr[c] ? x
    CLAIM cli
      cli[c] ! 42
    CLAIM cli
      cli[c] ! MOSTNEG INT

This is somewhat cumbersome, given the simple nature of what we're trying to do -- share a single channel. An equivalent version, using anonymous channel types, is:

SHARED! CHAN INT c:
PAR
  SEQ i = 0 FOR 2
    INT x:
    c ? x
  CLAIM c!
    c ! 42
  CLAIM c!
    c ! MOSTNEG INT

This is much easier to follow, and it is still largely clear what is going on.

Anonymous channel-types are created by use of the "SHARED" keyword in an ordinary channel declaration. By default, both ends of the anonymous channel type will be shared, unless restricted by an additional "?" or "!" (as in the above fragment). Two restrictions apply to anonymous channel-types. Firstly, whenever referred to by name, a channel-direction specifier must be used to indicate the client or server end (e.g. "c!" for the client-end). Secondly, anonymous channel types may not be assigned or communicated, but they may be renamed. The one exception is that the compiler allows an anonymous channel-type to be used as a parameter for a FORKed process. Additionally, the KRoC run-time system supports anonymous channel-types for the standard top-level parameters (in addition to different combinations of top-level parameters). For example:

PROC say.hello (SHARED CHAN BYTE out!)
  VAL []BYTE message IS "hello, forked and shared world!*n":
  CLAIM out!
    SEQ i = 0 FOR SIZE message
      out ! message[i]
:

PROC example (CHAN BYTE kyb?, SHARED CHAN BYTE scr!)
  FORKING
    SEQ
      FORK say.hello (scr!)
      FORK say.hello (scr!)
:

As can be inferred from the above example, when an anonymous channel-type is used as a formal parameter, any restriction on the SHARED can be omitted.

Inside the body of a CLAIM an anonymous channel-type behaves like an ordinary occam channel. This includes renaming, which is not allowed for ordinary mobile channel-types. Typical usage, for example:

#USE "course.lib"

PROC simple (SHARED CHAN BYTE scr!)
  PAR
    CLAIM scr!
      out.string ("hello world 1!*n", 0, scr!)
    CLAIM scr!
      out.string ("hello world 2!*n", 0, scr!)
:

OEP/116 (last edited 2007-09-27 00:23:48 by ats1)