p1 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. .NH
  2. Introduction
  3. .PP
  4. Occam [1] is a programming language which is based on the concepts of
  5. concurrency and communication. These concepts enable today's applications of
  6. microprocessors and computers to be implemented more effectively.
  7. .PP
  8. An Occam program consists of a (dynamically determined) number
  9. of processes communicating through channels.
  10. To communicate with the outside world some predefined channels are needed.
  11. A channel has only one writer and one reader; it carries machine words and
  12. bytes, at the reader/writer's discretion. The process with its communication
  13. in Occam replaces the procedure with parameters in other languages (there are
  14. no procedures in Occam).
  15. .PP
  16. In addition to the normal assignment statement, Occam has two more
  17. information-transfer statements, the input and the output:
  18. .DS
  19. .ft CW
  20. chan1 ? x -- reads a value from chan1 into x
  21. chan2 ! x -- writes the value of x onto chan2
  22. .ft
  23. .DE
  24. Both the outputting and the inputting processes wait until the other is there.
  25. Channels are declared and given names. Arrays of channels are possible.
  26. .PP
  27. Processes come in 5 varieties: sequential, parallel, alternative,
  28. conditional and repetitive. A process starts with a reserved word telling
  29. its nature, followed by an indented list of other processes. (Indentation
  30. is used to indicate block structure.) It may be preceded by declarations.
  31. The processes in a sequential/parallel process are executed sequentially/in
  32. parallel. The processes in an alternative process have guards based on the
  33. availability of input; the first to be ready is executed (this is waiting
  34. for multiple input). The conditional and repetitive processes are normal
  35. \fBIF\fPs and \fBWHILE\fPs.
  36. .PP
  37. \fIProducer-consumer example:\fP
  38. .DS
  39. .ft CW
  40. .nf
  41. CHAN buffer: -- declares the channel buffer
  42. PAR
  43. WHILE TRUE -- the producer
  44. VAR x: -- a local variable
  45. SEQ
  46. produce(x) -- in some way
  47. buffer ! x -- and send it
  48. WHILE TRUE -- the consumer
  49. VAR x:
  50. SEQ
  51. buffer ? x -- get a value
  52. consume(x) -- in some way
  53. .ft
  54. .fi
  55. .DE
  56. .bp
  57. .PP
  58. Processes can be replicated from a given template; this combines
  59. with arrays of variables and/or channels.
  60. .PP
  61. \fIExample: 20 window-sorters in series:\fP
  62. .DS
  63. .ft CW
  64. .nf
  65. CHAN s[20]: -- 20 channels
  66. PAR i = [ 0 FOR 19 ] -- 19 processes
  67. WHILE TRUE
  68. VAR v1, v2:
  69. SEQ
  70. s[i] ? v1; v2 -- wait for 2 variables from s[i]
  71. IF
  72. v1 <= v2 -- ok
  73. s[i+1] ! v1; v2
  74. v1 > v2 -- reorder
  75. s[i+1] ! v2; v1
  76. .fi
  77. .ft
  78. .DE
  79. .PP
  80. A process may wait for a condition, which must include a comparison
  81. with \fBNOW\fP, the present clock value.
  82. .PP
  83. Processes may be distributed over several processors; all processes
  84. under a \fBVAR\fP declaration must run on the same processor. Concurrency can be
  85. improved by avoiding \fBVAR\fP declarations, and replacing them by \fBCHAN\fP
  86. declarations. Processes can be allocated explicitly on named processors and
  87. channels can be connected to physical ports.