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

The function:

  random (maxvalue, seed)

returns an (INT, INT) value. How can I assign the first INT in the pair to one variable, and the second to another? I have tried:

  INT number, seed:
  SEQ
    ...
    (number, seed) := random (maxvalue, seed)

But I imagined it would cause an error ... and it did.

Answer 21:

If you look at the syntax of the function declaration:

  INT, INT FUNCTION random (VAL INT upto, seed)

you will see that it returns an INT, INT - i.e. no brackets! The correct syntax, therefore, is:

    number, seed := random (maxvalue, seed)

For further information on this function, see Question 77 (2000). For general questions about animating the Dining Philosphers' problem, see last year's Question 66 (2000) onwards.

Keywords: q7 , random


Question 22:

On slide 6-70 of the occam notes you say:

Modify the fork process so that it guarantees service on each input - even if the other one is perpetually busy. No philospher must starve because of greedy colleagues!

My question is what service should it guarantee on each input? What do you mean by service?

Answer 22:

From a low-level point of view, service in occam always means accepting a channel input. High-level viewpoints depend on the high-level semantics of the process being considered.

In this case, the service performed by a fork is being-picked-up. What needs to be guaranteed is that, if philosopher 3 is sitting next to a continuously ravenous philosopher 2, philosopher 2 doesn't always get the fork. With the given code, there is no such guarantee. Phil 2 could be eating when phil 3 arrives at the table and reaches for the fork it shares with phil 2 and blocks. Eventually, phil2 finishes eating and puts down that fork ... only to become immediately hungry (zero thinking time!) and race back to the table and reach for the fork again. If that happens before the fork process has looped back to the start of its loop, the fork will see both phils trying to pick it up. With a plain ALT, it might let phil 2 pick it up. This could continue for ever!

To eliminate, the fork must fair ALT over those input channels it is servicing.

Keywords: q7


Question 23:

What is the difference between:

  out ! FLUSH

and:

  flush (out)

Answer 23:

None! As you can see by looking at the source code in /usr/local/work/co516/libsrc/utils.occ:

  PROC flush (CHAN OF BYTE out)
    out ! FLUSH
  :

Keywords: flush


Question 24:

This is more of an anonymous observation really. I'm sitting here looking at q7.occ and, to be honest, I haven't got the first clue on how to start this assesment. I've been to the lectures and the classes, but me along with quite a few others who I have been talking to over the weekend have got no idea. I appreciate that yes some people have managed to do it, but the others are struggling.

Plus also after talking with my friends we all realised that nobody says anything in the classes apart form a select few which makes for an uncomfortable atmosphere when the postgrad is standing in front of a bunch of students who don't say anything for an hour. Perhaps it would have been better to concentrate more on the dining philosophers assessment in classes? I haven't got many notes on it at all.

Answer 24:

The assessment was set last November, when you had enough technical information to solve it. The occam variant PROTOCOL makes the solution neater and that was introduced by the end of last term. The first two seminar classes this term were devoted to explaining the assessment and talking through the recomended way to solve it. If you 'haven't got many notes on it at all', that is not our fault. That assistance was provided six weeks ago and the assessment could have been completely finished at that time. Last weekend is a bit late to start on this work and complain that you do not know what to do.

Fully participating in seminars is crucial to getting the best out of them. We try to get everyone involved to our best ability and sometimes do not succeed. Sometimes this is our fault. However, if a student has done no preparation for the seminar (e.g. has not worked on the exercises being discussed in between seminars), then that student will find it difficult to contribute to the seminar and will feel uncomfortable.

Keywords: q7


Question 25:

For the dining philosophers, I have created my own display process as required. However, I am not sure how to link all the processes together in a network under the q7 process. Any help??

Answer 25:

This is a bit too general a question to answer -- need your source code to point to what you're doing wrong.

All I can offer is this. The q7 process has the screen channel -- plug that into your display along with the (newly declared) report channels, whose other ends are attached to your modified secure.college. Hope that helps.

Keywords: q7


Question 26:

Do we really need the q7 process, because I place my display process in the secure.college process?

Answer 26:

It's the q7 process that has the screen channel, along with the other compulsory channels in its parameter list that are needed for the starting process of the (kroc) occam executable. If you give that parameter signature to your secure.college and make that process the last one in your source code, then that will work fine. But that has bundled up your display process inside your college.

I would prefer the college logic to be independent of its display. That way, we can change the display logic (e.g. to drive some graphics window) without having to touch the college.

Keywords: q7


Question 27:

I am having trouble modifing the fork process in the dining philosopher's question. What I want to do is basically have a fair ALTing process going over the two input lines, left and right.

I have already implemented a fair ALTing process in my animate process, but the difference there was that all the input lines were called the same name -- i.e. state[0], state[1] etc., so implementing it there was easy from the definition given in the notes. The problem with the fork process is that the input lines have two distinct names, and so the definition of fair ALTing does not translate as obviously.

What I have tried to do is give them the same name, so in the fork header I have put '[]CHAN OF BOOL in', but I could not get it to work this way after many attempts. My question is: is this the correct way to be going about altering fork?

Answer 27:

There are two ways. One is to create a channel array abbreviation for the two scaler channels - i.e.

  [2]CHAN OF BOOL c IS [left, right]:

Normal anti-aliasing rules now apply - you can't use the names left and right anymore (because you have the new names, c[0] and c[1], for them). But you now have an array of channels and the usual fair ALTing coding (see slide 10-23) can now be applied.

Second way: don't be clever and just write:

  WHILE TRUE
    SEQ
      PRI ALT              -- first give left priority
        left ? ..
          ..
        right ? ..
          ..
      PRI ALT              -- then give right priority
        right ? ..
          ..
        left ? ..
          ..

Keywords: q7 , fair-alt


Question 28:

WOW!!! I just found:

http://wotug.ukc.ac.uk/parallel/

It's an amazing site!! Why on earth you didn't mention that in the first lectures?!?! :))) I'm sure I'm not the only student who finds parallel programming interesting. Thanks. :)

Answer 28:

Thanks for the commendation! Yes, we put a lot of work into that a while back. Sadly, Dave Beckett (whose idea this all was) left us to join another team at Bristol University and we have had no funding to continue maintenance. You will notice its last modified date (01/03/2000) and that some of its links no longer work. It remains useful though, so we are keeping it on-line (but are no longer pushing it at the world ...).

Keywords: parallelism , wotug


Question 29:

Do we lose marks if our code has repeating sections - that is if it works according to specification can we still get full marks even if the code is very long?

Answer 29:

Yes -- I'm afraid you will lose marks for this. Source code must not only be correct, it must be easy to see that it is correct (and, hence, maintain). This means that elegance, neatness and simplicity matters. Code that needlessly repeats the same lines with only trivial differences (e.g. in some magic numbers) is none of the above.

Keywords: duplicating-code


Question 30:

Do we have to comment our code as it is fairly self explanatory and just makes the code look more unreadable?

Answer 30:

Comments should be used to clarify code. If they make it less readable, they are bad comments! Comments that confuse or add no information will be penalised - e.g.

  SEQ
    in ? x         -- input from channel 'in' into 'x'
    x := x + 1     -- increment 'x' by one

For further general comments about comments, see the answer to Question 12 (2001).

Keywords: comments

Referrers: Question 52 (2012)

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.