© P. H. Welch1 Lego-Land ™ Chapter 5. © P. H. Welch2 … some simple networks.

Slides:



Advertisements
Similar presentations
Programming in Occam-pi: A Tutorial By: Zain-ul-Abdin
Advertisements

Models of Concurrency Manna, Pnueli.
Statement-Level Control Structures
Expressions and Statements. 2 Contents Side effects: expressions and statements Expression notations Expression evaluation orders Conditional statements.
(C) P. H. Welch1 Chapter 4 Fundamentals of occam.
Compiling Communicating Processes into Delay-Insensitive VLSI Circuits Alain J. Martin Department of Computer Science California Institute of Technology.
Objectives Using functions to organize PHP code
1 CSE1301 Computer Programming: Lecture 15 Flowcharts and Debugging.
Chapter 5: Loops and Files.
Alice in Action with Java
Chapter 8: Introduction to High-level Language Programming Invitation to Computer Science, C++ Version, Third Edition.
1 CSE1301 Computer Programming: Lecture 15 Flowcharts, Testing and Debugging.
Chapter 8 Arrays and Strings
C++ for Engineers and Scientists Third Edition
Chapter 8: Introduction to High-level Language Programming Invitation to Computer Science, C++ Version, Third Edition.
Chapter 8: Introduction to High-Level Language Programming Invitation to Computer Science, C++ Version, Fourth Edition.
CONTROL STATEMENTS Lakhbir Singh(Lect.IT) S.R.S.G.P.C.G. Ludhiana.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Parallel & Concurrent Programming: Occam Vitaliy Lvin University of Massachusetts.
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 l Array Basics l Arrays in Classes and Methods l Programming with Arrays.
High-Level Programming Languages: C++
Chapter 5: Control Structures II (Repetition)
EGR 2261 Unit 5 Control Structures II: Repetition  Read Malik, Chapter 5.  Homework #5 and Lab #5 due next week.  Quiz next week.
CS5204 – Operating Systems 1 Communicating Sequential Processes (CSP)
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
Chapter 8 Arrays and Strings
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 4: Control Structures I (Selection)
1 Chapter 4: Selection Structures. In this chapter, you will learn about: – Selection criteria – The if-else statement – Nested if statements – The switch.
Today  Table/List operations  Parallel Arrays  Efficiency and Big ‘O’  Searching.
Chapter 8: Arrays.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Arrays.
1 Arrays An array is a collection of data values, all of which have the same type. The size of the array is fixed at creation. To refer to specific values.
PHP Programming with MySQL Slide 4-1 CHAPTER 4 Functions and Control Structures.
Chapter 5: Control Structures II (Repetition). Objectives In this chapter, you will: – Learn about repetition (looping) control structures – Learn how.
CS Midterm Study Guide Fall General topics Definitions and rules Technical names of things Syntax of C++ constructs Meaning of C++ constructs.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 8 Arrays.
JavaScript, Fourth Edition
Alice in Action with Java Chapter 5 Lists and Arrays.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 6 Functions.
Flow of Control Chapter 3. Outline Branching Statements Java Loop Statements Programming with Loops The Type boolean.
Introduction to Loops Iteration Repetition Counting Loops Also known as.
Copyright Curt Hill Arrays in C/C++ What? Why? How?
Chapter 8 Testing. Principles of Object-Oriented Testing Å Object-oriented systems are built out of two or more interrelated objects Å Determining the.
Loops and Files. 5.1 The Increment and Decrement Operators.
Lecture 4: Looping Tami Meredith. Back to Basics... Programming requires: 1. Identification of the problem. 2. Solving the problem: A. Selecting the data.
Winter 2006CISC121 - Prof. McLeod1 Stuff No stuff today!
Spring 2006CISC101 - Prof. McLeod1 Announcements Assn 4 is posted. Note that due date is the 12 th (Monday) at 7pm. (Last assignment!) Final Exam on June.
55:032 - Intro. to Digital DesignPage 1 VHDL and Processes Defining Sequential Circuit Behavior.
Visual C# 2005 Using Arrays. Visual C# Objectives Declare an array and assign values to array elements Initialize an array Use subscripts to access.
1 CSE1301 Computer Programming: Lecture 16 Flow Diagrams and Debugging.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 7A Arrays (Concepts)
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
CONDITIONALS CITS1001. Scope of this lecture if statements switch statements Source ppts: Objects First with Java - A Practical Introduction using BlueJ,
C++ for Engineers and Scientists Second Edition Chapter 4 Selection Structures.
Introduction to Algorithms
MATLAB: Structures and File I/O
Java Programming: Guided Learning with Early Objects
Some occam- Basics Co631 (Concurrency)
Choice and Non-Determinism
CMSC 202 Java Primer 2.
Message Protocols Co631 (Concurrency)
CSCE 314: Programming Languages Dr. Dylan Shell
Replicators (components and test-rigs)
Introduction to Algorithms
Replicators (components and test-rigs)
Testing & Security Dr. X.
Presentation transcript:

© P. H. Welch1 Lego-Land ™ Chapter 5

© P. H. Welch2 … some simple networks

© P. H. Welch3 ‘Legoland’ Catalog inout succ inout tail in out.0 out.1 black.hole in n n out id in out + + in.0 in.1 out

© P. H. Welch4 PROC id (CHAN OF INT in, out) WHILE TRUE WHILE TRUE INT x: INT x: SEQ SEQ in ? x in ? x out ! x out ! x: PROC succ (CHAN OF INT in, out) WHILE TRUE WHILE TRUE INT x: INT x: SEQ SEQ in ? x in ? x out ! x + 1 out ! x + 1: PROC black.hole (CHAN OF INT in) WHILE TRUE WHILE TRUE INT x: INT x: in ? x in ? x: inout succ in id in out

© P. H. Welch5 PROC plus (CHAN OF INT in.0, in.1, out) WHILE TRUE WHILE TRUE INT x.0, x.1: INT x.0, x.1: SEQ SEQ PAR PAR in.0 ? x.0 in.0 ? x.0 in.1 ? x.1 in.1 ? x.1 out ! x.0 + x.1 out ! x.0 + x.1: PROC delta (CHAN OF INT in, out.0, out.1) WHILE TRUE WHILE TRUE INT x: INT x: SEQ SEQ in ? x in ? x PAR PAR out.0 ! x out.0 ! x out.1 ! x out.1 ! x: in out.0 out in.0 in.1 out

© P. H. Welch6 PROC prefix (VAL INT n, CHAN OF INT in, out) SEQ SEQ out ! n out ! n id (in, out) id (in, out): PROC tail (CHAN OF INT in, out) SEQ SEQ INT any: INT any: in ? any in ? any id (in, out) id (in, out): scope of any inout tail n n inout

© P. H. Welch7 Theorem n n tail id is a blocking FIFO buffer of capacity 6 Theorem 

© P. H. Welch8 succ 0 0 numbers out integrate in pairs out tail + + in p p + q p + q + r p + q + r + s p q r s... p q r s... q + p r + q s + r t + s...

© P. H. Welch9 PROC numbers (CHAN OF INT out) CHAN OF INT a, b, c: CHAN OF INT a, b, c: PAR PAR delta (a, out, b) delta (a, out, b) succ (b, c) succ (b, c) prefix (0, c, a) prefix (0, c, a): PROC integrate (CHAN OF INT in, out) CHAN OF INT a, b, c: CHAN OF INT a, b, c: PAR PAR delta (a, out, b) delta (a, out, b) prefix (0, b, c) prefix (0, b, c) plus (in, c, a) plus (in, c, a): PROC pairs (CHAN OF INT in, out) CHAN OF INT a, b, c: CHAN OF INT a, b, c: PAR PAR delta (in, a, c) delta (in, a, c) tail (a, b) tail (a, b) plus (b, c, out) plus (b, c, out): succ 0 0 numbers out a b c integrate in a b c pairs out tail + + in a c b

© P. H. Welch10 Sequential Version numbers out PROC numbers (CHAN OF INT out) INT n: INT n: SEQ SEQ n := 0 n := 0 WHILE TRUE WHILE TRUE SEQ SEQ out ! n out ! n n := n + 1 n := n + 1: 0, 1, 2, 3, …

© P. H. Welch11 PROC integrate (CHAN OF INT in, out) INT total: SEQ total := 0 WHILE TRUE INT x: SEQ in ? x total := total + x out ! total : Note: each declaration is as local as possible out in integrate p, p + q, p + q + r, p + q + r + s, …p, q, r, s, … Sequential Version

© P. H. Welch12 pairs 0 0 fibonacci out 1 1 squares out numbers integrate pairs

© P. H. Welch13 PROC squares (CHAN OF INT out) CHAN OF INT a, b: PAR numbers (a) integrate (a, b) pairs (b, out) : PROC fibonacci (CHAN OF INT out) CHAN OF INT a, b, c, d: PAR delta (a, b, out) pairs (b, c) prefix (0, d, a) prefix (1, c, d) : pairs 0 0 fibonacci a outbc 1 1 d squares a b numbers pairs integrate

© P. H. Welch14 PROC demo (CHAN OF BYTE out) [4]CHAN OF INT c: PAR numbers (c[0]) squares (c[1]) fibonacci (c[2]) times (c[3]) lay.out (c, out) : Note: use of channel array demo c[0] c[2] c[3] out c[1] numbersfibonacci squares times lay.out

© P. H. Welch15... replicators

© P. H. Welch16 PAR i = 0 FOR 4 in[i] ? x[i] means PAR in[0] ? x[0] in[1] ? x[1] in[2] ? x[2] in[3] ? x[3] INT declaration number of replications first value x in[0] in[1] in[2] in[3]

© P. H. Welch17 The Sort Pump cell out in out c[1] in c[13]c[0]

© P. H. Welch18 VAL INT total IS 16: PROC sort (CHAN OF BYTE in, out) [total-2]CHAN OF BYTE c: PAR cell (in, c [0]) PAR p = 1 FOR total-3 cell (c[p-1], c[p]) cell (c[total-3], out) : This is a “pump” of 15 cells – i.e. it can sort groups of up to 16 items

© P. H. Welch19 VAL BYTE mark IS 255: PROC cell(CHAN OF BYTE in, out) -- in ? {{data}* mark}* -- ASSUME: mark > data WHILE TRUE BYTE max: SEQ in ? max WHILE max <> mark BYTE n: SEQ in ? n IF -- output smaller and keep larger max >= n out ! n TRUE -- i.e. max < n SEQ out ! max max := n out ! mark : cell out in

© P. H. Welch20 sort test rig in out main a b a b out in m[3] probe.out probe.in m[1] m[0] m[2] test.rig keys window (16, 2) lay.out window (48, 2) screen

© P. H. Welch21 Test Rig Components Keys:filters user input; rejects erroneous input (and issues error report), compresses/encodes legal inputfor onward transmission. Screen:multiplexes message streams to single output channel. Window:fixed-size delay line, dumps entire contents to some screen “window” on every change of state. Layout:lays out results of previous tests.

© P. H. Welch22 Design Guidelines one function = one process multiple functions = parallel processes each function programmed from its own point-of-view (“object-oriented” design)

© P. H. Welch23 PROC main (CHAN OF BYTE in, out) CHAN OF BYTE a, b: PAR sort (a, b) test.rig (in, out, b, a) : PROC test.rig (CHAN OF BYTE in, out, probe.in, probe.out) CHAN OF BYTE a, b: [4]CHAN OF BYTE m: PAR keys (in, a, m[0]) window (16, 2, a, probe.out, m[1]) // top-left window (48, 2, probe.in, b, m[2]) // top-right lay.out (b, m[3]) screen (m, out) :

© P. H. Welch24 Parallel Implementation of the Sort Cell PROC cell (CHAN OF BYTE in, out) CHAN OF BYTE a, b, c: PAR gt (in, b, c, a) sub (hi, lo, a, b) sub (lo, hi, c, out) : > in out lo hi lo b a cell c.

© P. H. Welch25 a b out in PROC sub (VAL BYTE a, b, CHAN OF BYTE in, out) SEQ out ! b WHILE TRUE BYTE x: SEQ in ? x IF x = a out ! b TRUE out ! x :

© P. H. Welch26 PROC gt (CHAN OF BYTE in.0, in.1, small, large) WHILE TRUE BYTE x.0, x.1: SEQ PAR in.0 ? x.0 in.1 ? x.1 IF x.0 < x.1 PAR small ! x.0 large ! x.1 TRUE PAR small ! x.1 large ! x.0 : large > in.0 in.1 small.

© P. H. Welch27 Non-Deterministic Construct ALT Guarded Process

© P. H. Welch28 Guard Attributes A guard may be ready or not-ready. A not-ready guard may change to ready as a result of external activity. A ready guard may be executed. A guard may be simple or pre-conditioned. The following definition assumes all the guards are simple:

© P. H. Welch29 Alt Semantics if no guard is ready, the process is suspended until one (or more) is ready if one guard is ready, execute it and then execute the process it was defending (end of Alt process) if more than one guard is ready the system arbitrarily chooses one of them, executes it and then executes the process it was defending (end of Alt process) An ALT process executes as follows: Only one “guarded process” executes.

© P. H. Welch30 Simple Guard Input Guard in ? x An input guard is ready if a parallel process has output to that channel and is waiting acknowledgement of its data. An input guard executes like an input process.

© P. H. Welch31 crude.plex in.0 in.2 in.1 out PROC crude.plex (CHAN OF INT in.0, in.1, in.2, out) WHILE TRUE INT x: ALT in.0 ? x out ! x in.1 ? x out ! x in.2 ? x out ! x :

© P. H. Welch32 Simple Guard Timeout Guard tim ? AFTER t A timeout guard is ready if the value on the tim channel (always available and increasing) is AFTER the (fixed) value of t. It has a null execution.

© P. H. Welch33 PROC watch (VAL INT max.gap, CHAN OF INT in, out, CHAN OF BOOL panic) WHILE TRUE TIMER tim: INT x, t: SEQ tim ? t ALT in ? x out ! x tim ? AFTER t PLUS max.gap panic ! TRUE : in out panic watch (max.gap)

© P. H. Welch34 Simple Guard Skip Guard TRUE & SKIP A skip guard is always ready. It has a null execution. Its main application is for polling input channels to see if data is pending (but only in conjunction with PRI ALT – see later). However: ALT TRUE & SKIP x := 42 TRUE & SKIP x := 43 Do either assignment – you choose!

© P. H. Welch35 The skip guard always has to be written with a pre-condition. Pre-conditioned guards will be explained later. For all simple guards, the pre-condition is TRUE. This is why the simple skip guard is written in such a strange way. There is no good reason why a skip guard must have a pre-condition. It is just the cautious nature of the language. Skip guards should not be used too freely!

© P. H. Welch36 Deterministic Choice PRI ALT “Guarded” Process If more than one guard is ready, the first one in the order of listing is chosen for execution.

© P. H. Welch37 Polling To poll a channel to see (& take) if there is data pending: PRI ALT in ? x... data was present - execute this code TRUE & SKIP... data was not present - execute this code WARNING: polling is a rather expensive and dangerous technique! Be vary sparing in its use. Only use when absolutely essential.

© P. H. Welch38 Simple Multiplexor De-Multiplexor plex in[] out de.plex in out[]

© P. H. Welch39 PROC plex ([]CHAN OF INT in, CHAN OF INT out) WHILE TRUE INT x: ALT i = 0 FOR SIZE in in[i] ? x SEQ out ! i out ! x : PROC de.plex (CHAN OF INT in, []CHAN OF INT out) WHILE TRUE INT i, x: SEQ in ? i in ? x out[i] ! x : Note the replicated ALT

© P. H. Welch40 Channel Protocols It is a good idea to document the structure of information flowing through the channels: plex n n de.plex item* (channel number, item)* occam2 supports much of this in the language Use comments to document the rest

© P. H. Welch41 Sequential Protocol PROC plex ([]CHAN OF INT in, CHAN OF CHAN.INT out) WHILE TRUE INT x: ALT i = 0 FOR SIZE in in[i] ? x out ! i; x : PROC de.plex (CHAN OF CHAN.INT in, []CHAN OF INT out) WHILE TRUE INT i, x: SEQ in ? i; x out[i] ! x : PROTOCOL CHAN.INT IS INT; INT:

© P. H. Welch42 Sequential Protocol PROC plex ([]CHAN OF BYTE in, CHAN OF CHAN.BYTE out) WHILE TRUE BYTE x: ALT i = 0 FOR SIZE in in[i] ? x out ! i; x : PROC de.plex (CHAN OF CHAN.BYTE in, []CHAN OF BYTE out) WHILE TRUE INT i: BYTE x: SEQ in ? i; x out[i] ! x : PROTOCOL CHAN.BYTE IS INT; BYTE:

© P. H. Welch43 multi.plex in[] out de.multi.plex in out[] Channel number followed by a variable length packet Variable length packets of data: count a “length” count followed by that number of items items (e.g., 5, -77, 2, 12, 4, 99)

© P. H. Welch44 Packet Multiplexer (raw) multi.plex in[] out PROC multi.plex ([]CHAN OF INT in, CHAN OF INT out) WHILE TRUE ALT i = 0 FOR SIZE in INT length: in[i] ? length SEQ out ! i out ! length SEQ j = 0 FOR length INT x: SEQ in[i] ? x out ! x : Replicated ALT Declared only for the guarded process Guarded process Guard

© P. H. Welch45 Packet De-Multiplexer (raw) de.m.plex in out[] PROC de.m.plex (CHAN OF INT in, []CHAN OF INT out) WHILE TRUE INT i, length: SEQ in ? i in ? length out[i] ! length SEQ j = 0 FOR length INT x: SEQ in ? x out[i] ! x :

© P. H. Welch46 Array Protocol PROTOCOL PACKET IS INT::[]REAL64: UNFORTUNATELY: occam2 does not allow us to re-use user-named protocols in these definitions. Instead, we have to expand them down to their primitive names: PROTOCOL CHAN.PACKET IS INT; INT::[]REAL64: count array PROTOCOL CHAN.PACKET IS INT; PACKET:

© P. H. Welch47 User supplies multi.plex with a buffer sufficiently large for each application instance of this process.User supplies multi.plex with a buffer sufficiently large for each application instance of this process. With PROTOCOL s, channels securely carry structured messages (with mixed types).With PROTOCOL s, channels securely carry structured messages (with mixed types). multi.plex (buffer) in[] out PROC multi.plex ([]REAL64 buffer, []CHAN OF PACKET in, []CHAN OF CHAN.PACKET out) WHILE TRUE ALT i = 0 FOR SIZE in INT length: in[i] ? length::buffer out ! i; length::buffer : Higher-level expression (implicit inner loop) Faster execution

© P. H. Welch48 User supplies de.multi.plex with a buffer sufficiently large for each instance of this process.User supplies de.multi.plex with a buffer sufficiently large for each instance of this process. de.multi.plex (buffer) in out[] PROC de.multi.plex ([]REAL64 buffer, CHAN OF CHAN.PACKET in, []CHAN OF PACKET out) WHILE TRUE INT i, length: SEQ in ? i; length::buffer out[i] ! length::buffer : Higher-level expression (implicit inner loop) Faster execution

© P. H. Welch49 Three Monitors mon in[] alarm mon in[] alarm limits mon in[] alarm control limits

© P. H. Welch50 Protocols for the Monitors PROTOCOL MY.DATA IS INT: PROTOCOL ALARM.MESSAGE IS INT; INT: offending channel number offending value

© P. H. Welch51 PROC mon.0 ([]CHAN OF MY.DATA in, CHAN OF ALARM.MESSAGE alarm) -- Sends an “alarm” if any input is out of the -- range An “alarm” is the offending input -- range An “alarm” is the offending input -- channel number, followed by the offending value. -- channel number, followed by the offending value. : mon in[] alarm PROC mon.0 ([]CHAN OF MY.DATA in, CHAN OF ALARM.MESSAGE alarm) -- Sends an “alarm” if any input is out of the -- range An “alarm” is the offending input -- range An “alarm” is the offending input -- channel number, followed by the offending value. -- channel number, followed by the offending value. WHILE TRUE ALT i = 0 FOR SIZE in INT x: in[i] ? x IF (x 60) alarm ! i; x alarm ! i; x TRUE SKIP :

© P. H. Welch52 Protocols for the Monitors PROTOCOL MY.DATA IS INT: PROTOCOL ALARM.MESSAGE IS INT; INT: offending channel number offending value PROTOCOL LIMITS.MESSAGE IS INT; INT: lower limit upper limit

© P. H. Welch53 PROC mon.1 ([]CHAN OF MY.DATA in, CHAN OF ALARM.MESSAGE alarm, CHAN OF LIMITS.MESSAGE limits) : PROC mon.1 ([]CHAN OF MY.DATA in, CHAN OF ALARM.MESSAGE alarm, CHAN OF LIMITS.MESSAGE limits) WHILE TRUE ALT i = 0 FOR SIZE in INT x: INT x: in[i] ? x in[i] ? x IF IF (x hi) (x hi) alarm ! i; x alarm ! i; x TRUE TRUE SKIP SKIP : mon in[] alarm limits PROC mon.1 ([]CHAN OF MY.DATA in, CHAN OF ALARM.MESSAGE alarm, CHAN OF LIMITS.MESSAGE limits) INT lo, hi: SEQ SEQ limits ? lo; hi limits ? lo; hi WHILE TRUE PRI ALT limits ? lo; hi SKIP SKIP ALT i = 0 FOR SIZE in INT x: INT x: in[i] ? x in[i] ? x IF IF (x hi) (x hi) alarm ! i; x alarm ! i; x TRUE TRUE SKIP SKIP : PROC mon.1 ([]CHAN OF MY.DATA in, CHAN OF ALARM.MESSAGE alarm, CHAN OF LIMITS.MESSAGE limits) INT lo, hi: SEQ SEQ limits ? lo; hi limits ? lo; hi ALT is This ALT is nested!

© P. H. Welch54 ALTPRIALT Nested ALT s and PRI ALT sALT ALT  ALT ALT The inner ALT disappears!

© P. H. Welch55 ALTPRIALT Nested ALT s and PRI ALT sALT ALT i = 0 FOR n ALT ALT ALT... 

© P. H. Welch56 ALTPRIALT Nested ALT s and PRI ALT s ALT We could not do this without nested ALTs! ALT ALT i = 0 FOR n ALT... 

© P. H. Welch57 PROC mon.1 ([]CHAN OF MY.DATA in, CHAN OF ALARM.MESSAGE alarm, CHAN OF LIMITS.MESSAGE limits) : PROC mon.1 ([]CHAN OF MY.DATA in, CHAN OF ALARM.MESSAGE alarm, CHAN OF LIMITS.MESSAGE limits) WHILE TRUE ALT i = 0 FOR SIZE in INT x: INT x: in[i] ? x in[i] ? x IF IF (x hi) (x hi) alarm ! i; x alarm ! i; x TRUE TRUE SKIP SKIP : mon in[] alarm limits PROC mon.1 ([]CHAN OF MY.DATA in, CHAN OF ALARM.MESSAGE alarm, CHAN OF LIMITS.MESSAGE limits) INT lo, hi: SEQ limits ? lo; hi WHILE TRUE PRI ALT limits ? lo; hi SKIP SKIP ALT i = 0 FOR SIZE in INT x: INT x: in[i] ? x in[i] ? x IF IF (x hi) (x hi) alarm ! i; x alarm ! i; x TRUE TRUE SKIP SKIP : PROC mon.1 ([]CHAN OF MY.DATA in, CHAN OF ALARM.MESSAGE alarm, CHAN OF LIMITS.MESSAGE limits) INT lo, hi: SEQ limits ? lo; hi ALT is This ALT is nested!

© P. H. Welch58 Guards Pre-Conditioned Guards Any simple guard may be prefixed by a Boolean expression: & ALTPRI ALT When the ALT (or PRI ALT ) starts execution, any pre-conditions on the guards are evaluated. FALSE If a pre-condition turns out to be FALSE, that guarded process is not chosen for execution – even if the (simple) guard becomes ready.

© P. H. Welch59 in.0 out in.1 in.2 INT a, b: SEQ... set a and b TIMER tim: INT time.out, x: SEQ tim ? time.out time.out := time.out PLUS 1000 ALT in.0 ? x out ! x in.1 ? x out ! x (a > 0) & in.2 ? x out ! x (b > 0) & tim ? AFTER time.out out ! –1 RUN-TIME DECISION do we listen to the in.2 channel? do we set the time-out?

© P. H. Welch60 Protocols for the Monitors PROTOCOL MY.DATA IS INT: PROTOCOL ALARM.MESSAGE IS INT; INT: offending channel number offending value PROTOCOL LIMITS.MESSAGE IS INT; INT: lower limit upper limit PROTOCOL CONTROL.MESSAGE IS INT; BOOL: channel number “on” or “off”

© P. H. Welch61 mon in[] alarm control limits PROC mon.2 ([]CHAN OF MY.DATA in, CHAN OF ALARM.MESSAGE alarm, CHAN OF LIMITS.MESSAGE limits, CHAN OF CONTROL.MESSAGE control, []BOOL ok) -- assume: (SIZE in) = (SIZE ok) INT lo, hi: SEQ... initialise... main cycle... main cycle :

© P. H. Welch62 --{{{ main cycle WHILE TRUE PRI ALT limits ? lo; hi SKIP INT line: control ? line; ok[line] control ? line; ok[line] SKIP SKIP--}}} --{{{ main cycle WHILE TRUE PRI ALT--}}} ALT i = 0 FOR SIZE in INT x: INT x: ok[i] & in[i] ? x ok[i] & in[i] ? x IF IF (x hi) (x hi) alarm ! i; x alarm ! i; x TRUE TRUE SKIP SKIP--}}} --{{{ main cycle WHILE TRUE PRI ALT limits ? lo; hi SKIP SKIP--}}} --{{{ initialise SEQ limits ? lo; hi SEQ i = 0 FOR SIZE ok ok[i] := TRUE–– initially listen to all inputs ok[i] := TRUE –– initially listen to all inputs--}}} … in[] alarm control limits mon.2 guard is This guard is pre-conditioned!

© P. H. Welch63 INT declaration number of replications first value PAR PAR i = start FOR count Replicators (Summary) INT declaration ALT ALT i = start FOR count number of replications first value

© P. H. Welch64 INT declaration number of replications first value SEQ SEQ i = start FOR count Replicators (Summary) INT declaration IF IF i = start FOR count number of replications first value

© P. H. Welch65 INT declaration number of replications first value SEQ SEQ i = start FOR count Replicators (Summary) for for (int i = start; i < (start + count); i++) { } In Java or C: Must not change the value of Must not change the value of i

© P. H. Welch66 INT declaration IF IF i = start FOR count number of replications first value Replicators (Summary) nested IF -replication This performs a ‘bounded sequential search’ – but needs a nested IF -replication in case the search fails …

© P. H. Welch67 IF IF IF i = 0 FOR SIZE a some.condition (a[i])... you found it at index i TRUE... you didn’t find it   ... you didn’t find it    Bounded Sequential Search (occam) a Find the first element of an array, a, that matches some condition …

© P. H. Welch68 int i = 0; bool bool found = false; for for (i = 0; i < a.length; i++) { if if (some.condition (a[i])) { found = true; break; } if if (found) {... you found it at index i... you found it at index i } else {... you didn’t find it   ... you didn’t find it    } Bounded Sequential Search (Java/C) a Find the first element of an array, a, that matches some condition …