Initial revision
This commit is contained in:
87
doc/occam/p1
Normal file
87
doc/occam/p1
Normal file
@@ -0,0 +1,87 @@
|
||||
.NH
|
||||
Introduction
|
||||
.PP
|
||||
Occam [1] is a programming language which is based on the concepts of
|
||||
concurrency and communication. These concepts enable today's applications of
|
||||
microprocessors and computers to be implemented more effectively.
|
||||
.PP
|
||||
An Occam program consists of a (dynamically determined) number
|
||||
of processes communicating through channels.
|
||||
To communicate with the outside world some predefined channels are needed.
|
||||
A channel has only one writer and one reader; it carries machine words and
|
||||
bytes, at the reader/writer's discretion. The process with its communication
|
||||
in Occam replaces the procedure with parameters in other languages (there are
|
||||
no procedures in Occam).
|
||||
.PP
|
||||
In addition to the normal assignment statement, Occam has two more
|
||||
information-transfer statements, the input and the output:
|
||||
.DS
|
||||
.ft 5
|
||||
chan1 ? x -- reads a value from chan1 into x
|
||||
chan2 ! x -- writes the value of x onto chan2
|
||||
.ft
|
||||
.DE
|
||||
Both the outputting and the inputting processes wait until the other is there.
|
||||
Channels are declared and given names. Arrays of channels are possible.
|
||||
.PP
|
||||
Processes come in 5 varieties: sequential, parallel, alternative,
|
||||
conditional and repetitive. A process starts with a reserved word telling
|
||||
its nature, followed by an indented list of other processes. (Indentation
|
||||
is used to indicate block structure.) It may be preceded by declarations.
|
||||
The processes in a sequential/parallel process are executed sequentially/in
|
||||
parallel. The processes in an alternative process have guards based on the
|
||||
availability of input; the first to be ready is executed (this is waiting
|
||||
for multiple input). The conditional and repetitive processes are normal
|
||||
\fBIF\fPs and \fBWHILE\fPs.
|
||||
.PP
|
||||
\fIProducer-consumer example:\fP
|
||||
.DS
|
||||
.ft 5
|
||||
.nf
|
||||
CHAN buffer: -- declares the channel buffer
|
||||
PAR
|
||||
WHILE TRUE -- the producer
|
||||
VAR x: -- a local variable
|
||||
SEQ
|
||||
produce(x) -- in some way
|
||||
buffer ! x -- and send it
|
||||
WHILE TRUE -- the consumer
|
||||
VAR x:
|
||||
SEQ
|
||||
buffer ? x -- get a value
|
||||
consume(x) -- in some way
|
||||
.ft
|
||||
.fi
|
||||
.DE
|
||||
.bp
|
||||
.PP
|
||||
Processes can be replicated from a given template; this combines
|
||||
with arrays of variables and/or channels.
|
||||
.PP
|
||||
\fIExample: 20 window-sorters in series:\fP
|
||||
.DS
|
||||
.ft 5
|
||||
.nf
|
||||
CHAN s[20]: -- 20 channels
|
||||
PAR i = [ 0 FOR 19 ] -- 19 processes
|
||||
WHILE TRUE
|
||||
VAR v1, v2:
|
||||
SEQ
|
||||
s[i] ? v1; v2 -- wait for 2 variables from s[i]
|
||||
IF
|
||||
v1 <= v2 -- ok
|
||||
s[i+1] ! v1; v2
|
||||
v1 > v2 -- reorder
|
||||
s[i+1] ! v2; v1
|
||||
.fi
|
||||
.ft
|
||||
.DE
|
||||
.PP
|
||||
A process may wait for a condition, which must include a comparison
|
||||
with \fBNOW\fP, the present clock value.
|
||||
.PP
|
||||
Processes may be distributed over several processors; all processes
|
||||
under a \fBVAR\fP declaration must run on the same processor. Concurrency can be
|
||||
improved by avoiding \fBVAR\fP declarations, and replacing them by \fBCHAN\fP
|
||||
declarations. Processes can be allocated explicitly on named processors and
|
||||
channels can be connected to physical ports.
|
||||
Reference in New Issue
Block a user