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 61:

When will we have access to the answers for the previous assessment? (q4) I belive viewing this would be useful to help in the new assessment, many thanks.

Answer 61:

I can't immediately see how the solution to Q4 would be useful for Q6, except in that it is working occam code. We'll probably make the solution available this week, however, together with the model-answer to Q5.

The course notes and on-line resources ought to provide sufficient information, in addition to the material discussed in the seminars.

Keywords: model-answers


Question 62:

Are the solutions to 'q4' and 'q5' going to become available, as they are not available as of yet?

Answer 62:

We will endeavour to make those solutions available this week.

Keywords: model-answers


Question 63:

Where can we find the `libsrc' directory? I've had a hunt around raptor and I cant seem to find it anywhere.

Answer 63:

From UNIX, the directory is:

 
    /usr/local/courses/co516/libsrc/

From windows:

    \\raptor\files\courses\co516\libsrc\

Keywords: course-library

Referrers: Question 111 (2004)


Question 64:

Am I correct in thinking the command line to run the program would be along the lines of (assuming `data.txt' is the data going in):

    data.txt | q6

?

Answer 64:

Not quite, see the answer to Question 52 (2000). What you probably meant for the above was:

    raptor$ cat data.txt | ./q6

Keywords: q6 , keyboard-input


Question 65:

I can't figure out the best way to have all the values read out once the cells are full (using the pipeline implementation). The way I thought of doing was to have the `poison', marking the end of the input, sent along to each cell along the pipeline. This would cause a toggle in each cell to switch meaning that the cell would output the `poison' to the next cell and then output what it contains and then outputs everything it recieves from then on. Only problem is that doing this means the `poison' is moved to the end of the queue to the front and outputted first into the `display', meaning no outputs are put on screen.

Could you give me a few hints as to a way I could trigger all cells to start outputting their contents without moving the `poison' from being the last output? Sorry if this isnt clear!

Answer 65:

As you suggest, poison should be the last thing happening. The `read.data' process only outputs the poison after it has output all the data. Your cells should follow suit -- the `poison' tag should only be sent once any data in the cell has been sent (effectively the reverse of what you appear to be doing at the moment).

Keywords: q6 , poison


Question 66:

After using `make.string' on the BYTE arrays so I can compare them, is it ok to continue using them as BYTE arrays afterwards, or is there something I need to do to turn them back ?

Answer 66:

They're still BYTE arrays (adjusted slightly to allow the string utilities to work), so yes, continue using them in that way.

Keywords: q6


Question 67:

For q6, is it ok for the program to terminate by deadlocking?

i.e. when all of the data has been read in, processed and outputted to the screen, should the program end with the error message:

    program deadlocked no processes to run

Or do we need to terminate the program in some other way?

Answer 67:

The program should terminate cleanly, i.e. without deadlock. Using the poison tag, this should not be too hard to achieve. Just arrange for each process to exit its loop when it receives poison, tidy up and output poison (if it has an output channel) and finish its code!

Marks will be lost if your solution simply deadlocks when done.

Keywords: q6


Question 68:

is an empty string represented as ""

e.g. `equal.string(name,"")' would check if the name varible was empty

Answer 68:

Yes, that comparison will return TRUE, if at some point, previously, this happened:

    make.string (name, 0)

Keywords: q6 , string-handling


Question 69:

when a `[]BYTE' is first declared, is it initialised to "" ?

Answer 69:

No, but occam won't let you declare things like that. The following, for example, won't compile:

    []BYTE a:
    [0]BYTE b:
    SEQ
      ...

All array declarations must have a constant size:

    [42]BYTE a:
    [SIZE a]INT b:
    SEQ
      ...

The initial contents of arrays are undefined -- occam does not initialise them in any way. If you want them initialised, you must do it explicitly.

Keywords: arrays


Question 70:

I'm really having trouble trying to output all the results,

I looked at the previous questions and got the idea for a toggle but came with problem that to set a toggle it will have to send a poison first each time, because the contents of that cell and would end up with nothing being outputted

Answer 70:

I'm afraid I don't fully understand your question. What do you mean by `toggle' ?

The general behaviour of the `read.data' process is:

That is the order of things which the `display' process expects. I.e. it does:

Thus, any processes that you put inbetween these should (must) follow the same pattern of communication.

Keywords: q6


Question 71:

For:

    PROC make.string([]BYTE a, VAL INT length)

it doesnt output to anything it seems, unlike the `copy.string'

does this means it just changes the variable passed to it for the string part to the length that is passed to it?

ie if we had:-

    []BYTE name1:
    INT length1:

    make.string(name1, length1)

would this change the variable `name1' to be the length passed to it?

Answer 71:

Yes, it modifies the contents of the array passed to it as a parameter. The array itself is left untouched.

In your code fragment, you have this:

    []BYTE name1:

This is an illegal declaration. The array-size must be given, e.g.:

    [max.name.length]BYTE name1:

Also, when you call `make.string (name1, length1)', it's important that `length1' has been initialised -- perhaps to zero.

Keywords: string-handling


Question 72:

I have written and compiled my code and I get this error...

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

I have checked the previous anon qs as suggested and have, as far as I know, checked the following...

  1. both the string and poison protocol cases are being dealt with
  2. the array indexes used in my sort-pump are the same as in the example code
  3. my comparison case deals with the three options (string.more, string.less, string.same)

I can't think of any of the other things mentioned in the previous anon q's that I can check (I'm not using any ALT or IF statements)

Any suggestions??

Answer 72:

Without seeing your code, it is hard to answer your question. Please e-mail your supervisor with your code to get help.

If you have access to KRoC/Linux (installed on `gonzo'), you can compile with debugging and see where abouts the error is occuring. See the answer to Question 30 (2003) for how to do this.


Question 73:

On Q6 am I right in thinking that both the make.string and compare.string are done inside the individual cells?

Is it also right that when the first `NAME.NUMBER' is passed to the cells from collate.marks the tempoary string for holding that cells name is empty and it just takes the first name its given as its cell name from now on?

If Im right in my understanding, then the names will not come out in alphebetical order will they?

To get the names and thier respective marks out in alphabetical order, will I need to collect them in an array once poison has been called and then compare them again?

Answer 73:

Yes, make.string and compare.string should be done inside the cell processes.

On your second question, yes, the cell is initially `empty'. When the first name/mark input arrives, the cell should store it. As a point, collate.marks shouldn't do anything (computational or communication) if you're using a pipeline of cell processes -- it just sets up the pipeline.

On your third point, yes, the output will not be sorted (unless the input was).

Sorting the names alphabetically is not required for this assignment -- it's just nice. However, collecting data in an array and sorting there is definitely not the right way, unless you didn't use a pipeline of cells. See the lecture notes on the `sort-pump'.

Keywords: q6


Question 74:

When is the deadline for Q7?

Answer 74:

From the course assessments page, Thursday of week 18 (12th February)


Question 75:

When will we have all of the information presented in lectures to be able to do q7? Thanks.

Answer 75:

You have had all the technical knowledge needed for q7 since around week 10 last term. Precise details of what is required by way of animation to get full marks, together with fairly detailed suggestions as to how that may be implemented, is being presented and discussed in the seminar groups (weeks 13-15). Attendance at seminar groups is, of course, compulsory ...

Keywords: q7


Question 76:

Hi, I'm just experimenting with my animation for q7 and I've come across an annoying problem with protocols in occam. My problem is that each channel seems to have a buffer. This creates a problem in protocol channels because there is no FLUSH like with the screen output. This means I have forks multiplying all over the place and philosiphers jumping around in mad bursts, despite huge delays tha are supposed to be in their movement. Is there any way of creating the effect of FLUSH on a protocol channel?

Answer 76:

Channels have no buffers - no matter what their protocol. So you have to explain/analyse your problem a bit more. Once a channel output has completed, the other side has definitely taken it. Your channel output does not complete because the channel has buffered your message in some way.

If what you want is for the outputting process *not* to continue until the inputting process has completed some response to its input, you need to program that - e.g.:

    PROTOCOL THING
      CASE
        data; ...                  -- the message types
	other; ...                 -- other message types
	...
        complete                   -- only accepted once response is complete

Then the sending process:

    SEQ
      ...  stuff
      c ! data; ...
      c ! complete                 -- wait for response (e.g. animation) to complete
      ...  more stuff

and the receiving process:

    c ? CASE
      data; ...
        SEQ
          ...  response (e.g. animation)
          c ? CASE
	    complete               -- let sender know all is done
	      SKIP
      other; ...
        SEQ
          ...  response (e.g. animation)
          c ? CASE
	    complete               -- let sender know all is done
	      SKIP

Note: here is a little bit more of occam! If a CASE input only deals with one case (as in the above), it can be shortened to a one-liner:

    c ? CASE
      data; ...
        SEQ
          ...  response (e.g. animation)
          c ? CASE complete        -- let sender know all is done
	  SKIP
      other; ...
        SEQ
          ...  response (e.g. animation)
          c ? CASE complete        -- let sender know all is done
	  SKIP

If the response to that one case is SKIP, that response can, of course, be now omitted:

    c ? CASE
      data; ...
        SEQ
          ...  response (e.g. animation)
          c ? CASE complete        -- let sender know all is done
      something.else; ...
        SEQ
          ...  response (e.g. animation)
          c ? CASE complete        -- let sender know all is done

Hope that helps! [Note: you only need to engage in such trickery if you have more than one process doing animation. If you have just the one and it does some animation in response to a received message, then that animation will complete before it processes the next message and does the next animation. This is all that's needed to do the minimum form of animation required for full marks - as shown by the executable model answer (answers/a7). However, to get parallel animation - see some of the other example answers - you will naturally need parallel processes and tricks as outlined above.]

Keywords: q7

Referrers: Question 106 (2003)


Question 77:

Hi! I a find occam very difficult and was wondering if there is going to be an overview lecture or two soon? There is so much info to take in that I don't feel I have a proper grasp of it yet. I find working out whether the system will deadlock or not difficult to determine, and also when to use parallel and when to use sequential. Whenever I program something in occam I have countless errors even though I think I have computed it correctly. This worries me as in the exam we obviously will not have the benefit of a compiler. Can I suggest that some optional terminal sessions are set up almost as drop-ins, as a lot of people in my seminar group are finding it easy? Thanks.

Answer 77:

The remainder of my part of this course consists of the real-time material (chapter 8 of the slides and the paper: "Managing Hard Real-Time ...") and JCSP (which presents a Java class library giving exactly the same occam/CSP concurrency model). The JCSP material will review the fundamental ideas that have already been presented for occam. There are only a few such ideas and they are simple. But they have to be mastered.

Deadlock analysis is not particularly simple but, so long as you are fluent in the concurrency mechanisms of the occam/CSP model, it becomes not unreasonable. If you think it's hard in occam, try it for the standard Java threads model!

If you don't understand when to use PAR and when to use SEQ, then you have not understood anything about the concurrency model and you have to do something about it. Have you not been attending the weekly seminar groups where all the ideas are rehearsed as you discuss the assignments? We provide these seminar groups precisely to enable you to raise any issues - especially fundamental technical principles - with your seminar leader and group.

You should not be getting "countless errors" when compiling occam code. We provided 4 (or 5) weeks of terminal classes last term specifically to assist you in mastering the basic syntax and structure of the language and in understanding the compiler error messages. If you are now getting countless error messages, you do not have such basic mastery ... and how can you have got by the first three assessment exercises?

Basic syntax and structure is given on slides 4-22, 4-26 .. 4-30, 4-33 .. 4-35, 5-27 and 5-36. Some extra stuff is on 10-5 .. 10-6, 10-10 .. 10-22. Of course, smeantics is also discussed there. Everything is spelt out in words in the "occam2 Checklist" paper (17 pages). And there are examples everywhere else. But it all must be read and re-read and discussed and re-read. And you must draw/design lots and lots of process icons and network diagrams and write lots and lots of code.

We already provide - through the weekly seminars - far more help for this course than you will find available for many others. I do not think magic assitance at terminal classes will have much educational benefit at this stage in the course. If completely stuck in understanding why your program won't compile, ask a friend, your seminar leader or me (phw) directly. Only puzzle over the first few error messages from any compiler - fix those and then re-compile. View the occam compiler expecially as your friend - it just won't let you do anything silly and prevents you from making a great range of more subtle mistakes. It ensures you know about the scope of declarations and the scope of programming structures. Learn the very simple rules, let your programs compile and they will work ...

Finally, when marking exam scripts, minor errors in syntax are ignored - so long as the overall logic and structure can be seen. You are not being assessed in the exam on trivial mistakes that the compiler would put you right upon if presented with your code. Indented layout, however, needs to be (rouhgly) right because that shows up the logical structures. But indenting hand-written code costs no time and should be automatic.

Keywords: overview , exams


Question 78:

I'm quite confused on how I can assign each philosopher an identity. I've modified the header of the PROC philosopher in the following way:

    PROC philosopher(CHAN OF INT id, CHAN OF BOOL left, right,down, up, CHAN OF MESSAGE report)

This means that the display PROC has 16 input channels. I'm not sure this is the right way of doing it.

Answer 78:

Assigning IDs to the philosophers is better done by simply using a ``VAL INT'', passed to each philosopher from the PAR replicator that sets the network up.

Communicating the ID to each philosopher (using the `id' channel you added) is certainly possible, but definitely not the simplest way.

Keywords: par , q7


Question 79:

Having problems with q7. In our seminar we were told to use:

    i, seed := random (n, seed)

to create a random number. Can you explain what each of the elements are, also can you give a basic example.

This part of the Philosopher proc is going to be a base for all 5 philosophers, but there is the problem of each having the same random number for each one. Do we need to have a different value of `n' and `seed' each time the PROC is run? Or is this dealt with by the random function ?

Answer 79:

The `seed' is there to initialise the random number generator. More specifically, it is the internal state of the `random' function -- functions cannot retain their own state.

Before you call `random' for the first time, you need to initialise `seed' to a number between 1, and the maximum positive integer minus one. When you call `random' for a second time, use the new `seed' returned by the first call, and so on.

Yes, you need a different starting seed for each philosopher (hint: each philosopher has a different `id').

`n' is the range of the random number generated. i.e. `random' will return a random value between 0 and (n-1); in your example, assigned to `i'.

Keywords: random , q7

Referrers: Question 33 (2007)


Question 80:

Can we still get full marks on q7 if we just do a basic line by line 'animation' of what is going on ?

Answer 80:

If you have just a scrolling output of events, the answer is no. The minimum solution (that can get full marks) is a table-driven animation, shown by the `a7' example answer. This can be found on raptor in the `/usr/local/courses/co516/answers/' directory.

Keywords: q7

Referrers: Question 88 (2003)

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.