XML

kent logo

CO538 Anonymous Questions and Answers Keyword Index

This page provides a keyword index to questions and answers. Clicking on a keyword will take you to a page containing all questions and answers for that keyword, grouped by year.

To submit a question, use the anonymous questions page. You may find the keyword index and/or top-level index useful for locating past questions and answers.

Keyword reference for replicator

2010

Question 23 (2010):

Submission reference: IN1918

In a replicated ALT is there a way to place a SKIP guard at the end? I have tried placing it at various points such as:

  ALT i = 0 FOR 10
    in[i] ? y
      ...  do stuff here
    SKIP

But I get a incorrect indentation error.

Answer 23:

A replicated ALT must have one (and only one!) guarded process indented below it – see slide 110 of "choice". So, your replicated ALT finishes with the "... do stuff here" line – and the indentation level returns to that of the ALT. Your SKIP is not at that level, so it's an indentation error (as the compiler correctly reports).

If you really want a SKIP guard to follow a replicated ALT, we must use a nested ALT (slides 123-133 of "choice"). The particular form you need is similar to the use of a replicated IF in slides 92-93 of "replicators":

  PRI ALT
    ALT i = 0 FOR 10
      in[i] ? y
        ...  do stuff here
    SKIP
      ...  do this if no in[i] channels are ready

Note that, as for all un-conditioned SKIP guards, the governing ALT must be PRIioritised – otherwise, the compiler would be correct to throw away the entire ALT and leave just the code reaction to the SKIP (because it's always ready and, therefore, may always be chosen!).

However, are you sure you want that SKIP guard? That would be a poll (see slide 30 in "choice") of all the channels in the 'in' array ... and polling is, usually, a more complex and inefficient way of doing the right thing ... in occam-pi anyway! See Question 32 (2004) and this part of Fred's occam tutorial.

Keywords: replicator , alt , polling

2007

Question 64 (2007):

Submission reference: IN1450

On the lecture on protocols, at the slide 55 what is the purpose of j? It is never being used.

Answer 64:

It's only there because, currently, occam-pi insists on their being a named replication variable and initial value (in a replicated SEQ, PAR, IF and ALT) – even if it's not used.

We might remove that insistence in the future – so that on that slide 55 we could write:

  SEQ FOR length
    INT x:
    SEQ
      in ? x
      out[i] ! x

When I get a moment, I'll add that to the list of occam enhancement proposals, :).

Keywords: replicator

2004

Question 60 (2004):

Hi, could you just give an explanation of how the following code works (taken from "sort_pump.occ"):

    PROC sort (CHAN OF BYTE in, out)
      [total - 2]CHAN OF BYTE c:
      PAR
        cell (in, c[0])
        PAR p = 1 FOR total - 3
          cell (c[p - 1], c[p])
        cell (c[total - 3], out)
    :

Thanks.

Answer 60:

This code creates a pipeline of processes (of `total - 1' cells) -- see slides 5-17 and 5-18. The two end cells are catered for specially (since these plug into the external environment -- via `in' and `out'). The cells between these are created using a replicated PAR. If you substitute a constant value for `total' (say 10), then expand and flatten the PAR replicator, it becomes a bit clearer:

    [8]CHAN OF BYTE c:
    PAR
      cell (in, c[0])

      cell (c[0], c[1])        -- PAR p = 1 FOR 7
      cell (c[1], c[2])        --   cell (c[p - 1], c[p])
      cell (c[2], c[3])
      cell (c[3], c[4])
      cell (c[4], c[5])
      cell (c[5], c[6])
      cell (c[6], c[7])

      cell (c[7], out)

Keywords: sort-pump , par , replicator


Question 29 (2004):

Just a quick question regarding sort_pump.occ. In the window process, does the following fill the buffer array with end markers?

  SEQ
    SEQ i = 0 FOR buff.max
      buffer[i] := end.marker
    ptr := 0

If so, what is the point of doing so?

Also, what does ptr mean? Is it some kind of field to keep track of the index of the array? Thanks.

Answer 29:

Yes. The statement "buffer[i] := end.marker" is replicated buff.max times in SEQuence, each with a different value for the control variable i (starting with zero, in this case, and incrementing by one each time).

We have to put something in the buffer since what is there initially gets pumped into the sorter as we type characters. We need something visible for display -- so zeroes (ASCII nulls) would not work. End markers work (they are mapped to visible dots for display) and they are harmless -- just ignore them (as does the lay.out process does if it sees consecutive markers!).

Note that in occam, there is no auto-initialisation of variables to default values (such as zero).

The answer to your last question is yes -- see the code labelled display buffer and update buffer, further down in the window process.

Keywords: replicator , sort-pump

2003

Question 95 (2003):

I was having problems putting the processes together using a replicator and was wonder if the code in the secure.college PROC create 6 philosophers instead of 5 as its is from 0 to 5

Answer 95:

Replicators in occam are as they seem: replication `FOR 5' means you get 5 replications.

By default, the replicator value increments by one, with the first replication having the `start' value. The general syntax for a replicator in occam is:

SEQ|PAR|ALT|IF  name  = start  FOR  count

KRoC/Linux additionally supports ``STEP  stride'' for replicators.

Keywords: replicator

Valid CSS!

Valid XHTML 1.0!

This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.
Last modified Mon May 20 13:50:32 2013
This document is maintained by Fred Barnes, to whom any comments and corrections should be addressed.