Chapter 5: Processes

This chapter describes Poly/ML's non-standard extensions for handling lightweight processes. The process model used is based on Milner's CCS. The structure Process contains the following:

type 'a channel
val channel : unit -> 'a channel
val send : 'a channel * 'a -> unit
val receive : 'a channel -> 'a

val fork : (unit -> unit) -> unit
val console : (unit -> unit) -> unit -> unit
val choice : (unit -> unit) * (unit -> unit) -> unit

val interruptConsoleProcesses : unit -> unit

channel () creates a new, unbuffered, channel.

send (c,x) writes the value x to the channel c. Since channels are unbuffered, the writing process is suspended until another process attempts to read from the channel c.

read c reads a value from the channel c and returns it. If no value is currently available on c, the reading process is suspended until another process attempts to write to that channel.

fork f creates a new process and executes the function call f () in it. The new process will not receive console interrupts i.e. typing <control-C> f will not raise the exception Interrupt in that process.

console f is like fork f except that the new process will be a console process. Typing <control-C> f will raise the exception Interrupt in all console processes but doesn't raise this exception in non-console processes. In addition, calling console f returns a function of type unit -> unit. Calling this function will raise the Interrupt exception in the new process only. This provides a more selective way to kill aberrant processes.

choice (f g) is a way to implement the choice primitive of CCS. It creates two processes which execute f() and g() respectively. However, these two processes are not independent: only one of them will be allowed to perform channels actions (sends and receives). As soon as one process successfully performs a channel action, the other process will block forever as soon as it attempts a send or receive. This relationship is also inherited by child processes; if any child process of f performs a channel action then all child processes of g will block. This behaviour allows calls of the function choice to be nested in order to create multiple-choice decision points.

interruptConsoleProcesses  raises Interrupt in all console processes.  It is equivalent to typing <control-C> f.

Copyright (c) 2000 CUTS and contributers.  Last updated: 15 January 2002 by David Matthews.