Processes

Processes form the fundamental unit of organization in occam, with multiple levels of processes interacting to form a working program. At the highest level, the entire application may be considered a process. Subroutines and other blocks of sequential code may also be considered processes, with different processes executed sequentially or in parallel. At the lowest level, individual lines of occam code are called primitive processes.

Primitive Processes

All occam programs consist of a combination of five primitive processes (Burns, 1988):
  1. STOP. The STOP process performs no action but never terminates. Calling STOP halts the parent process's execution, and is usually used to abort a program in response to a critical error condition.

  2. SKIP. The SKIP process is always ready to execute and terminates immediately without doing anything. SKIP is used to explicitly state that no action should occur, such as in the else clause of an IF statement.

  3. Assignment statements. In occam, assignment statements take the form:

    Variable := Expression.
    Variables in occam are strongly typed and must be declared, as described later in the data types section. Basically, a declaration names a data type for the new named variables and ends with a colon:

    INT x, y, z:
    BOOL done:
  4. Input and output statements. Occam processes may communicate with the environment or other processes using input and output statements, which function similar to assignments. The symbol ? is used for input and the symbol ! designates output:

          channel ! expression   -- Output expression to channel
    channel ? Variable     -- Read channel into variable

    All channel communications in occam are synchronous. When a process executes a channel read (?) statement, execution halts until another process executes a corresponding send (!) statement. Channels, like variables, must be declared, as described later with the data types. For example, an integer channel named C may be declared using the statement

    CHAN OF INT C:

Grouping and White Space

Occam's statements, called constructors, group primitive processes to form a program. The process constructors PAR and SEQ are the most basic constructors and are used to designate blocks of code which may be executed sequentially or in parallel. Other constructors, such as IF and WHILE, allow conditional or repeated execution of processes.

One of the most unusual aspects about occam is its use of white space as a determinant of code execution. Other languages, such as C and Java, use symbols like braces { and } to designate a unified body of code. In occam, a segment of code must be indented at a consistent level, with one statement per line, and preceded by a constructor.


The SEQ Sequential Process Constructor

The SEQ constructor specifies that the following block of processes should be executed sequentially. Again, each process must be indented at the same level with one process per line. For example, the following code reads an integer, modifies it, and writes it to an output channel:

      INT A:
      CHAN OF INT in, out:    
      SEQ
        in ? A
        A := A * 100
        out ! A
    


The PAR Parallel Process Constructor

The PAR constructor identifies a group of subprocesses are concurrent and may be executed in parallel. Concurrent processes must be completely independent. Some input operations or assignments may be trivially independent:

      INT A, B, C:
      CHAN OF INT in:          
      PAR
        in ? A
        B := B + 5
        C := 1
    


PAR and SEQ may be nested any number of times to create complex programs. For example, several SEQ blocks may be enclosed in a PAR block, identifying entire segments of sequential code that may be executed in parallel.

Association

One of the most important concepts in occam is the rule of association. First, "a sequence of sequences is itself a sequence" (Burns, 1988, p. 50). The following programs, where A, B, and C are processes, are equivalent:

      SEQ                  SEQ                  SEQ
        SEQ                  A                    A
          A                  SEQ                  B
          B                    B                  C
          C                    C
    


Second, parallel processes may be executed completely in parallel on different transputers or sequentially on a single transputer. Because the processes were specified as parallel, they contain no data dependencies, so occam may execute them in any order. Thus, they may be in any order in the source code. The following process specifications are equivalent:

      PAR                  PAR                  PAR
        A                    C                    B
        B                    A                    A
        C                    B                    C  
    


What is not obvious, however, is that occam reserves the right to determine if a SEQ process may actually be executed in parallel. If occam's dependency analysis determines that the procedures A and B are independent, it may elect to execute them in parallel, replacing SEQ with PAR:

      SEQ                  PAR
        A                    A
        B                    B
    


Now that primitive processes and communications are available for utilization, more complex constructions may be used to create useful programs.

Next: Constructions
Return to Index