OEP

115

Title

FORKed parallel processes

Summary

Allow processes to be spawned dynamically and joined later.

Owner

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

Status

Accepted

Date-Accepted

2002-09-01

Keywords

language fork

The "FORK" provides a means for dynamically creating a free-running parallel process. A type of "join" is available by use of a "FORKING" block, that acts as a barrier on which forked processes synchronise. If a FORK is not enclosed in any FORKING block, it runs freely.

The type of FORK supported is that of a new PROC instance. When instanced normally, PROC parameters use a renaming semantics. When FORKed, the parameters use a communication semantics. This means that non-communicable parameter types are not allowed in a FORK. This restriction is typically channel and reference parameters. However, if the need really arises, such things can be declared "#PRAGMA SHARED" and passed anyway. Any mobile type is, of course, allowed.

The use of "FORK" is likely to be application-specific (particularly useful for building server-farms -- see [Prioritised dynamic communicating processes: Part 2][pdcp2]. A simple example of the FORK is:

PROC big.sum (VAL []INT data)
  ...  spend some time processing and write results to file
:

PROC application (CHAN BYTE kyb?, scr!, err!)
  FORKING
    MOBILE []INT data:
    SEQ
      ...  allocate and initialise "data"
      FORK big.sum (data)
      ...  continue with application
:

After the FORK, "data" will remain defined. Since the formal parameter type is "VAL []BYTE", the data will be copied locally into the FORKed process, leaving the source (a mobile in this case) alone.

Connecting a FORK process to the rest of the process network is best done using mobile channel types or anonymous channel types. For example:

CHAN TYPE FOO
  MOBILE RECORD
    CHAN INT in?:
    CHAN INT out!:
:

PROC server (FOO? link)
  WHILE TRUE
    ...  do server stuff
:

PROC client (SHARED FOO! link)
  CLAIM link
    ...  do client stuff
:

PROC network ()
  FOO? f.s:
  SHARED FOO! f.c:
  SEQ
    f.s, f.c := MOBILE FOO
    FORK server (f.s)
    SEQ i = 0 FOR 10
      FORK client (f.c)
    ...  do some other stuff
:

[pdcp2]: http://www.cs.kent.ac.uk/pubs/2002/1512/

OEP/115 (last edited 2007-09-27 00:21:59 by ats1)