My occam-pi application has a long running producer process defined as follows:
PROC producer (VAL INT start, step, CHAN OF INT c!)
INT count:
SEQ
count := start
WHILE TRUE
SEQ
c ! count
count := count + step
:
It sends a value on the channel c
increasing from start
by step
. A full example is available here.
This works great, and I'm led to believe that infinite loops are idiomatic in CSP. The problem arises when my consuming algorithm is finished. In this example, a deadlock occurs once the consumer finishes.
The TAGGED.INT
protocol described here attempts to solve the problem of shutting down a network of processes, however, from my current understanding there is no simple method for terminating a producer whose primary job is sending on a channel. It feels like the only method of halting a producer is to use some sort of control channel and black hole the output:
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 -- necessary, only to kill the black hole process
SKIP
SEQ
c ! normal; count
count := count + step
:
A full working example is available here. The problem with this is that the code is much more unreadable - subjective, I know, but important for software engineering - the original intent is convoluted compared to the original. It seems contradictory to Occam's Razor!
With JCSP, C++CSP2 and python-csp a channel can be explicitly poisoned in order to shutdown a network of processes. For some reason wrangling occam to do this pollutes the code with shutdown logic and seems illogical.
So the question is, is there a method of terminating a producer process without the use of an explicit control
channel as in the example?
EDIT:
There is potentially more information on this topic contained within this mailing list archive (Poison), this is quite old (> 10 years). So the question still stands, has anything changed since then, or is this the best way of achieving 'process termination' in occam-pi?