CS452 - Real-Time Programming - Fall 2009
Lecture 29 - CSP
Reminders
- Train tracking 2: deadline reminder
- Train tracking 2: demos
- Final exam
CSP - Communicating Sequential Processes
Overall Context
- Collection of sequential processes. Examples
- Instantiated by
fork, terminated by wait(
)
- Or by Create
- Interprocess communication. Examples
pipe( )
- called before fork to let a parent and child process
communicate
- parent and child are in the same scope
- reader blocks until writer writes
- writer blocks only if the, in theory infinite, buffer is
full
socket( )
- server listens on a port; client connects to a port
- clients knows the ip address and port number of the server
- reader blocks until writer writes
Send( ) / Receive( ) / Reply( )
- client knows server through a magic name, just as for
sockets
- sender and receiver block until data flows from sender to
receiver
- reply unblocks sender coincident with data flow from receiver
to sender
CSP
Based on the concept of a channel
- one process writes on the channel
- another process reads from the channel
- read/write uses a protocol, which is roughly a data type
- reader blocks until writer writes
- writer blocks until reader reads
There has to be a way for the two processes to get hold of the same
channel. Examples,
- Parent instantiates channel
- Parent creates child passing channel id to child during
creation
- Parent and child communicate on channel
- Static (or dynamic) type checks ensure type safety on assignment to
input or from output
- Parent instantiates channel
- Parent creates two children, passing channel id to them during
creation
- Children communicate on channel
When CSP is provided by an operating system type safety is most likely to
be provided at run-time.
When CSP is provided by a programming language type safety can often be
provided at compile-time.
The Transputer
Use many co-operating, medium capability microCPUs to do a big job.
- An idea whose time has now come.
- Google
Problem is communication
- Big granularity (thick client: MS, Google)
- minimizes communication
- maximizes replicated data
- Small granularity
- minimizes replicated data
- maximizes communication
Comminication requires either
The transputer was an early, now vanished, example of the latter
- CPU, memory, switch on one chip
- chips connected in an array
- presumably a run-time system decides where tasks will go in order to
- maximize CPU throughput
- minimize communication overhead
Occam 2
Basic idea
- processes (tasks)
- may be named, take arguments and return values
- channels
- need a protocol (for type safety)
- must be named
- time
Combining processes
- sequential
- conditional
- if/then
- selection by case
- looping
- without test/break
- with test/break
- parallel
- initiated when the keyword PAR occurs.
- alternation
- guarded alternatives
- if more than one guard is true then select at random
Channels
- input
channel ? variable
- variable type must match protocol
- real-world hardware acknowledged by the anarchic protocol
- blocks when channel is empty
- output
channel ! value // the value of a variable or the result of an procedure
- variable type must match protocol
- blocks until an input process accepts the data
- input & output provide synchronization
- similar to sockets except for output blocking
Time
The Result
You can write a type-safe server, BUT
- all possible clients must be known at compile time.
Program structure is more static than is allowed in your system.
This might be a good thing.
Go
For comprehensive information: Go
here.
Return to: