XML

kent logo

CO538 Anonymous Questions and Answers

This page lists the various questions and answers. 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.

We have taken the liberty of making some minor typographical corrections to some of the questions as originally put. Although most of the questions here will have been submitted anonymously, this page also serves to answer some questions of general interest to those on the course.

When asking questions, please do not simply paste in your code and ask what is wrong with it, as these types of question are hard to answer in a public forum (resulting in either no answer, or an answer which will only be of use to the person asking the question). In many cases, a question about code can be formulated in general terms. For example, if you have an `IF' block that results in an `incorrect indentation' error, you might ask, ``what is the correct syntax for an occam `if' statement ?''. Questions of this form are easier to answer, and are meaningful to all.

Questions that are not suitable for these public pages (i.e. those that contain assignment-specific code), should be mailed to your seminar-leader.


Question 81:

I'm trying to get an idea of what a finished philosophers animation should look like, but can't run the model solutions located on raptor under `/usr/local/courses/CO516/answers/'. I get an ``access is denied'' error. Maybe this is intended but I'd like to know whether we should be thinking ASCII-art or Pixar quality graphics. Thanks.

Answer 81:

You probably just used the wrong case in the path (co516 not CO516). However, CO516 has now been linked to co516, so it should work.

As you'll see from the examples, we're expecting ASCII-art (well, varying degrees of, from a simple table-driven solution to a fully-featured spriteful ASCII animation). `Graphics' in occam is hard (at the moment, but we're working on it..!)


Question 82:

I keep getting the following error message when compiling q7:

-- stackdepth =  underflow !!!
-- stackdepth =  underflow !!!
KROC octran Version 1.0 for sparc-sun-solaris2.5.1
*** Integer stack underflow
...

I think it is because I'm choosing the wrong values to generate the random number. Can you give me some valid numbers I could use to see if my program is running properly. The code I have for thinking is:

    [snip code]

Answer 82:

This is not a normal error. Something in your code is breaking the compiler; please mail your code (that won't compile) to myself and David (frmb and dcw) and we'll have a look at it.

There have been a few incidences of compiler breakage in the past, some we've now cured in the Linux version. Most seem to be the result of completely broken/wrong occam. The code you pasted look pretty much valid, however, so please mail it to us and we'll take a look.


Question 83:

I am stuck trying to do the implementation of philosopher, I know that we should try and use a random time, but at the moment I am just trying to implement it with a static time, say 5 secs.

    [snip code]

Thats what ive done so far, and dont really know how to do the think and hungry stuff.

Thanks for any help

Answer 83:

We've mentioned this before, but posting large chunks of code to the anon Q+A page and simply asking what's wrong isn't particularly useful -- the anon Q+A is a group forum, not an individual forum. You question would have been better directed to your seminar leader.

The code you pasted is largely the default `philosopher' code, with some minor additions.

If you want to know about the `random' function or timeouts, see the keyword index entries for timers and random. Reading through the questions and answers for past questions (particularly relating to q7) should hopefully answer any questions you might have. Alternatively, talk to your seminar leader (preferably during the seminar).

Keywords: q7


Question 84:

In our seminar we were given the syntax to (a) create our own data type which is usefull for the coordinates and (b) fill the data type with values.

I can create my own data type with no trouble, but assigning a data type of:

    DATA TYPE COORDS
      RECORDS
        INT x,y:
    :

the way we were shown:

    [5] COORDS phil.pos[[*,*],[*,*],[*,*],[*,*],[*,*]]: (with the * as INT's)

doesn't work - I have tried messing about to get it to work but to no avail. Any obvious problems with this syntax?

Answer 84:

The syntax is nearly there, but not quite. Constants in occam aren't like variables; they're constants, not variables that you can't assign/input to. Thus the declaration of these is slightly un-expected. As a minor point, `RECORDS' in your data-type definition should just be `RECORD'.

The correct way to declare a set of constant co-ordinates (using your record type) would be:

    VAL []COORDS phil.pos IS [[*,*], [*,*], ...]:

You don't need to give the array-dimension explicitly here -- the compiler can count the number of things on the right-hand side.

If, however, you want to change these values as the program runs, you'd need a real variable array:

    [5]COORDS phil.pos:
    SEQ
      phil.pos := [[*,*], [*,*], ...]

.. or the shorter way using an INITIAL declaration.

See also the answer to Question 68 (2000).

Keywords: record-types , table


Question 85:

I'm trying to use the COORDS (shown in Q84) data type to pass the cordinates to `cursor.x.y'. However when using this code, (and `phil.think.pos' is a COORDS data type):

    VAL z IS INT x:
    cursor.x.y (phil.think.pos[z][0], phil.think.pos[1][z], out)

I get an error saying:

    "Expected a field name of COORDS, found a subscript expression"

pointing to the 2nd line. I know the positions aren't going to mean much but I'm just trying to get it to compile.

Answer 85:

By the look of it, `phil.think.pos' is an array of COORDS'. COORDS has two fields, `x' and `y'.

I'm a bit confused by your value-abbreviation of `x' -- why ? It's quite legal to write:

    INT x:
    SEQ
      x := 1
      cursor.x.y (phil.think.pos[x][x], phil.think.pos[x][y], out)

The compiler knows that the last square brackets (indexing the record-type) must be a field name. That name is different from the variable called `x'. If you need to rename it (for clarity), you can write:

    INT x:
    SEQ
      x := 1
      VAL INT i IS x:
      cursor.x.y (phil.think.pos[i][x], phil.think.pos[i][y], out)

The error comes about because you're trying to index a record-type with numbers (``[z][0]'' in your code) -- the compiler, as it says, is expecting a field name of COORDS.


Question 86:

I keep getting this error:

    KROC: Range error / STOP executed (signal 4)
    KROC: Fatal error code 1, core dumped
    Abort (core dumped)

what does it mean ?

Answer 86:

See the answers to Question 30 (2003) and Question 70 (2000).


Question 87:

Hi, what datatype does `cursor.x.y' take as im getting errors about wrong parameters.

Answer 87:

The `x' and `y' parameters are BYTEs. The PROC header for `cursor.x.y' is:

    PROC cursor.x.y (VAL BYTE x, y, CHAN BYTE out!)

See the answer to Question 7 (2000) for information on how to do a type-cast in occam.

Keywords: q7


Question 88:

I have some mystery regarding Q7 I'd like to clear up. As I understand it the college must communicate its status to the display process via a number of channels. I think the only thing the display process needs to know is the status of each philosopher; the status of security and the forks can be deduced if we know what the philosophers are doing.

As it stands the college is self contained and there is no obvious way to report, at any given time, its status to another process. One solution I can see is to replicate all communications between the processes in college, and route them to the display process. The display process would maintain its own picture of the college, which it updates according to the inputs on its channels. This seems rather complicated.

Alternately the display process could again recieve a copy of all internal college communications, but conforming to a protocol such that it can update its picture of the college without other information about its status. For example, when a philosopher wishes to sit down, instead of outputting a boolean he outputs a specific message the display process knows to mean "waiting to sit down" and can update its picture accordingly. This is assuming that the animation is not drawn frame at a time, but continuously updated as information comes in.

In these cases what does display need to communicate with in order to get a complete picture ? Security can tell it who is wanting to sit down and stand up, but it also needs to know the fork status. Presumably this will be the job of either forks or philosopher.

I have trawled the anonymous questions of old, none of the answers to which have baffled me, but I still cannot get this fundamental.

Answer 88:

All the questions you have asked have been discussed in your seminar groups for the last 4 weeks. These Q&A pages are in no way a substitute for attending those seminars. Your question suggests ideas that are either illegal (with respect to occam semantics) or far too complex. Simple solutions have been presented in the seminars.

Having said this, I will attempt to answer your questions. However, those who know how to do this problem should skip these answers, as correcting the confusion in your questions may confuse others unnecessarily.

In response to your first paragraph, yes, the state of the forks can be deduced from the philosopher, but it's easier to have the forks report their state. It also makes more sense; the state of a fork should be reported by the fork, not by something else.

You are sort of correct in your second paragraph, although I'm not sure what you mean by `replicate all communications'. Thankfully, setting up this extra `wiring' is not complicated in occam. However, the `display' process does not need to maintain the `state' of the college (see the next paragraph). The extra wiring can be handled using an array of channels; the `display' process gets the inputting ends as a `bundle' (array), whilst the outputting ends are distributed amongst the other processes. This will require some modifications to the `secure.college' process.

The third paragraph is essentially what we're expecting you to do for this assignment. The `philosopher', `fork' and `security' processes report their actions to the display as they happen. The display process just inputs these messages and draws on the screen accordingly. The animation should indeed be updated on-the-fly; it should not be done frame-by-frame. The only disadvantage is that the display cannot be completely redrawn (i.e. if it got corrupted, somehow). This isn't a problem for this assignment, however.

The various messages are best handled using a tagged protocol. The previous assignment, q6.occ, used a tagged protocol. The various `messages' have been discussed in the seminar groups. The q7.occ file gives some indication of what is required:

    Your task is to animate this demonstration.  Links will need to
    be made from the college to its external environment, through
    which the philsophers (and, maybe, the forks and the security guard)
    report their state.  These links are gathered by a fair-ALTing server
    that drives a screen display in response to incoming information
    from the college.  Thinking and eating by the philosphers should
    be modelled by random (but finite!) delays.  The animated display
    should reflect the round table in the dining room ...

Running the example solutions (on raptor, see Question 80 (2003)) should give you an indication of what is required -- i.e. what is being displayed (and therefore reported) there ? (`a7' is the example minimum-but-full-marks solution; the other example solutions are more animated).

Reporting by each process should be restricted to its own `state'. I.e., the security process should not report that philosophers are trying to stand up or sit down. This is actually very hard. The only state the security process maintains is how many philosophers are actually sat down -- it should report this. When a philosopher stands up or sits down, that should be reported by the philosopher -- not anything else. It is both more logical and simpler to have things this way, since it keeps the logic of each process `intact'. E.g. I might take your philosopher, fork, security and display processes, completely re-wire the nextwork (within reason), and still expect it to work. Having the correct functioning of processes depend on their external wiring is not really a good idea.. (such processes must conform to the protocol that they conceputally agreed on, however).

I hope this clears things up a bit. If you still have queries, or want some points explained in more detail, I'd suggest emailing or visiting your seminar-leader or other member of the course team (we all have a desk somewhere on campus).

Keywords: q7 , animation


Question 89:

Hi, I am having trouble with the `cursor.x.y' proc.

It will not accept the second parameter:

    INT id:
    ...
      [snip code]
      cursor.x.y (10, id, scr)

I thought an INT could be used as long as it isnt less than 0 or greater 255

Answer 89:

Such an INT can be used, but you need to cast it into a BYTE first. This can be done with: ``(BYTE id)''. If `id' is out of range for a BYTE, a run-time error occurs.

See also the answers to Question 74 (2000) and Question 73 (2000).

Keywords: cast

Referrers: Question 32 (2012) , Question 101 (2003)


Question 90:

For Q7 I am trying to use the `INTTOSTRING' routine in "convert.lib", so that I can directly output the id of a philosopher to the screen, rather than have a load of IF statements and duplicated code.

Currently I have:

    INT g:
    [5]BYTE string:
    INT n:

    INTTOSTRING (g, string, n)

but get "fatal symbol referencing errors" when I try to compile. It seems the compile goes ok, but the error occurs at linking.

I'm assuming we need to convert integers to []BYTE or CHAR at some point in the display process, or is there another way?

Answer 90:

Firstly, you don't need to use routines from Inmos libraries. Technically there's nothing wrong with them, though (some are particularly useful, like the routines that turn REAL64s into strings).

The linker is probably failing because you're not linking in the convert library -- you reference it from your code, but don't include it at compile time. The `course.lib' is special in this respect -- KRoC/Sparc (on raptor) automatically adds the `-lcourse' option when compiling programs. To get the Inmos conversion library linked in, just:

    kroc myfile.occ -lconvert

There may be inter-library dependencies, so other libraries might be needed too. `string.lib' is another (`-lstring' on KRoC's command-line).

Back to the main point, if you want to output an integer to the screen, just use `out.int'. This is in the course library and has been mentioned/ described many times in lectures and seminars. If you really want to turn INTs into an array of BYTEs, a better approach would be to use the code from the course library's `out.int', which is available on raptor in:

    /usr/local/courses/co516/libsrc/utils.occ

There are not many IFs, and hardly any duplicated code, though.

Keywords: out.int


Question 91:

I'm confused on how to get the forks to move correctly. Is it a better idea to have to separate tags for left and right forks (``left.fork'', ``right.fork'') or to just have one (e.g. ``fork; INT'') ?

Answer 91:

You need to mention what the `INT' is for, really. If it's the `id' of a fork, then that's one bit of information, but left/right is separate. Fork `i', for example, can be picked up or put down, by the philosopher on the left or right. The question is: do you need all this information from the fork, or just some of it, to do the animation ? -- watching the `a7' model answer should tell you this.

Keywords: q7


Question 92:

Are there any example source files of animation; I attended the seminar, but am having problems with even starting to animate.

Answer 92:

There were four seminars you should have attended ...

You could look at `test_utils.occ' in:

    /usr/local/courses/co516/examples

on Raptor. Or `examples/sort_pump.occ', but that uses `goto.x.y', which is now deprecated, rather than `cursor.x.y' (the two are essentially similar, however).

Essentially, text-animation is a repeating process of: move cursor, then output something. This can be seen most obviously in the `a7' model answer.

Source code for other animations can be found on Fred's occam page. These range from trivial to rather complex.

Keywords: animation , q7


Question 93:

I seem to have some problems with the security. If 4 philosophers are sitting, it reports that 3 philosophers are sitting until another philosopher moves: at that point it says that 4 philosophers are sitting. This is my code for the philosopher and security:

    [snip code]

Answer 93:

Usual things about not posting huge chunks of code to the anonymous Q+A page. This sort of question should be directed to your seminar leader.

However; the code you posted looks fine. Check that your `display' process flushes the output when that information is updated. The problem you describe sounds like a classic symptom of this.

Keywords: q7


Question 94:

I am having problems trying to ALT between my diplay input and security-guard on the `display' process. My code looks like..

    PRI ALT i = fav FOR count
      sec ? x
        ...
      in[i.mod.n] ? CASE
        ...

Answer 94:

Your layout is illegal, as the compiler is telling you. Look at slide 5-53 in the notes for the correct syntax, where a monitor process is also having to ALT between a single channel and an array of channels. This aspect of ALTs was stressed in the relevant lecture last term.

A replicated ALT may only contain one guard (that is replicated), or another ALT construct (that is also replicated accordingly). ALTs can be nested arbitrarily to construct `bigger' ALTs, so either:

    PRI ALT i = fav FOR count
      ALT
        sec ? x
          ...
        in[i.mod.n] ? CASE
          ...

This, however, replicated the `sec' input un-necessarily. Although this is not incorrect, it can be inefficient. Thus you pull the guard `outwards':

    ALT
      sec ? x
        ...
      PRI ALT i = fav FOR count
        in[i.mod.n] ? CASE
          ...

Question 95:

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


Question 96:

I'm trying to do a fair-ALT, but there are 11 channels to ALT over and thats a lot of of code! I was wondering is there a way of looping around FOR statements? What I mean is if the first time you write, say,

    ALT i = 0 FOR 5

is there anyway so that the second time I can write

    ALT i = 1 FOR 5

but have it so the 5th iteration loops back to channel 0 (i.e. the one I started on the first time). Sorry if thats unclear.

Answer 96:

I'm not sure what you're asking here -- at a guess you're confused as to the operation of a replicated-ALT. One key idea is that it is a replicator, not a loop as such. Writing:

    ALT i = 0 FOR 5
      in[i] ? x
        P(x)

is equivalent to:

    ALT
      in[0] ? x
        P(x)
      in[1] ? x
        P(x)
      in[2] ? x
        P(x)
      in[3] ? x
        P(x)
      in[4] ? x
        P(x)

For more information, look in the course notes that describe the ALT, around slide 5-29. The code for a fair-ALT is also given explicitly on slide 10-23, as you have been told many times! Also check out other related anonymous questions, particularly those on alternation and the fair-alt.

Keywords: fair-alt , q7


Question 97:

I have an input channel into `secure.college()' of type INT which will contain the ID for each philosopher and fork. This channel will be connected to both the philospher and fork PROCs. How do I make sure that I get a number that is one greater than the previous down the channel so that each philosopher has a unique ID?

Answer 97:

If you try and write code as you suggest above, the compiler will simply reject it (on a parallel (mis)usage error). Assigning IDs this way is hard. One question you should ask yourself is: ``do I really need to convey this information to the philosophers/forks using a channel communication ?''. The answer to that is: no. A `VAL INT id' parameter (for philosophers and forks) would be much simpler, and much clearer.

Keywords: q7


Question 98:

How do we submit q7 ? Do we just hand in the hard copy at the octagon or do we need to submit this electonically as well?

Answer 98:

The submission of the code will be electronic (so we can test/run your programs). You'll also need to submit a network diagram (on paper) to the CAS office. Keep an eye on the CS2 newsgroup for submission details (will be posted nearer the deadline).

Added later: submission directories have now been set up for you on raptor:

  /usr/local/proj/co516/q7-2004/your-login-name/      (Unix view)
  \\raptor\files\proj\co516\q7-2004\your-login-name\  (Windows view)
Please copy only your source code file(s) into there - usually this will just be one file called q7.occ. You can do this as often as you like up till the deadline - midnight, Thursday, 12th. February (that's the midnight between Thursday and Friday).

You must also submit a paper copy of all relevant network diagrams for your solution. These must correspond to your code submitted electronically, with all channels labelled with the names used in your code. Don't forget to indicate directions of channel flow. This copy may be machine produced or neatly drawn by hand. This part of the submission must be to the CAS office, with a cover sheet (copies of which will be in the Co516 pigeon hole, near CAS Reception), BEFORE they close at 4pm on that Thursday.

Keywords: q7


Question 99:

Hi. I have just installed Mandrake 9.2 and downloaded `kroc' & `gvim'. Is there a detailed readme suited to a non-unix person giving clear instructions on how to get an `.occ' file compiling using KRoC ? Thanks.

Answer 99:

When you install KRoC on Linux (running the `./build' script), it outputs a message directing you to some initial documentation:

    doc/essentially-kroc.txt

Compiling from the command-line is relatively simple. After you've source'd the KRoC setup file (that modifies your `PATH' environment variable):

    source /path/to/kroc/bin/setup.sh

(use `setup.csh' if you use csh or tcsh, although I'd stronly recommend bash -- that is probably the default).

To compile an occam file:

    kroc q7.occ -lcourse

As for gvim, install the Kent Vim Extensions following the instructions on:

http://www.informatico.de/kent-vim-ext/

Keywords: gvim , linux


Question 100:

My program just crashed spectaularly, and dumped a `core' file.

Can I use the `core' file for debugging?

Answer 100:

Unfortunately, the core that KRoC dumps is mostly useless -- there is no debugger that understands occam to the necessary degree, and the `core' file is from the wrong process..

To locate this sort of run-time error, you need a KRoC that supports run-time debugging. This is currently only available in KRoC/Linux. To turn debugging on, compile with the `-d' flag.

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:23 2013
This document is maintained by Fred Barnes, to whom any comments and corrections should be addressed.