Skip to content

Instantly share code, notes, and snippets.

@samgiles
Created April 23, 2014 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samgiles/11214993 to your computer and use it in GitHub Desktop.
Save samgiles/11214993 to your computer and use it in GitHub Desktop.
Full example of 'channel poisoning' for producer channels using a control channel [occam-pi]
#INCLUDE "course.module"
PROTOCOL CONTROL
CASE
poison
:
PROTOCOL TAGGED.INT
CASE
normal; INT
poison
:
PROC producer (VAL INT start, step, CHAN OF TAGGED.INT c!, CHAN OF CONTROL control?)
INT count:
INITIAL BOOL running IS TRUE:
SEQ
count := start
WHILE running
SEQ
PRI ALT
control ? poison
SEQ
running := FALSE
c ! poison
SKIP
SEQ
c ! normal; count
count := count + step
:
PROC blackhole (CHAN OF TAGGED.INT c?)
INITIAL BOOL flag IS TRUE:
INT any:
WHILE flag
c ? CASE
normal; any
SKIP
poison
flag := FALSE
:
PROC main (CHAN BYTE kyb?, scr!, err!)
CHAN OF TAGGED.INT c:
CHAN OF CONTROL control:
INITIAL INT n IS 0:
INT val:
PAR
producer(0, 4, c!, control?)
SEQ
WHILE n < 10
SEQ
c ? normal; val
out.int (val, 0, scr!)
out.string ("*n", 0, scr!)
n := n + 1
PAR
control ! poison
blackhole(c?)
:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment