Graphics Programs Reference
In-Depth Information
Figure 10.6: A spooler system
Spooler
while true
ALT
Chan 1 ? x :
for i=x-1 downto 0
P 1 Sp? pckt
h Print pckt i
endfor
Chan 2 ? x :
for i= x-1 downto 0
P 2 Sp? pckt
h Print pckt i
endfor
P 1
while true
h P 1 computes pckt[1..k] i
Chan 1 ! k
for i=k-1 downto 0
P 1 Sp! pckt[i]
endfor
endwhile
P 2
while true
h P 2 computes pckt[1..n] i
Chan 2 ! n
for i=n-1 downto 1
P 2 Sp! pckt[i]
endfor
endwhile
endwhile
Figure 10.7: A spooler system code
(Chan 2 and P 2 Sp) are the channels used for communication between the
process Spooler and process P 1 (P 2 ).
The corresponding Occam-like code is presented in Fig. 10.7. Process P 1
(P 2 ) executes a loop of computation and requests printing of the results.
If process P 1 (P 2 ) wants to send a sequence of packets to be printed to
the spooler, it first sends a message on channel Chan 1 (Chan 2 ) containing
a request to transmit k (n) packets and then enters a loop where at each
iteration it sends one of the k (n) packets on channel P 1 Sp (P 2 Sp). Process
Spooler executes a loop (the external one) in which it is willing to receive
the first available request to print from either of the two channels (ALT
command). If it receives a request for k(n) packets from Chan 1 (Chan 2 ) it
will then enter a loop of reception of k(n) messages from P 1 Sp (P 2 Sp).
The code presented in Fig. 10.7 is already in a form in which only control
structures that include PAR and communications have been kept. All other
operations are summarized within angle brackets. Fig. 10.8( a,b,c) presents
the results of the translation of each single process (P 1 , Spooler, and P 2 ,
respectively).
Observe how the for has been translated:
since the static
 
 
Search WWH ::




Custom Search