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:

For the Dining Philosopers Animation, can we get full or nearly full marks with a simple text output describing each state change?

Answer 81:

Around 20% of the marks are for a decent animation - where decent means at least to the standard of that given by:

    /usr/local/work/co516/answers/a7  (on raptor)

Keywords: q7


Question 82:

I am attempting to plex together multiple channels into one. Each channel uses a tagged protocol, STATUS, that I have defined. I have found a working solution:

  PROC plex ([]CHAN OF STATUS in, CHAN OF STATUS out)
    WHILE TRUE
      ALT i = 0 FOR SIZE in
        in[i] ? CASE
          INT v:
          sitting; v
            out ! sitting; v
          thinking;
            out ! thinking
          ...  same for all the other variants

However, I am not happy with this, since I am just switching based on what's in the protocol, and just outputting it in every case. What I want to be able to do is something like:

  PROC plex ([]CHAN OF STATUS in, CHAN OF STATUS out)
    WHILE TRUE
      ALT i = 0 FOR SIZE in
        STATUS s:
        in[i] ? s
          out ! s
  :

All my attempts at this have failed, usually resulting in:

    Error-oc-myq7.occ(117)- Name STATUS is not a TYPE.

Can you point me at the right syntax for this? Thanks.

Answer 82:

Your question is a very good one. I'm afraid that occam2.1 has no syntax to express your perfectly reasonable request! This problem occurs when writing many standard components for handling variant (CASE) protocols - buffers, message routers as well as multiplexors and de-mutiplexors. The proposed, but so far unimplemented, occam3 language enabled the declaration of UNION data-types, that would mostly solve this problem. The draft occam3 language specification can be found on:

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

for those interested (1.4 MBytes postscript). Summer or group project anyone?

Keywords: q7 , multiplex


Question 83:

How can I implement an ALT without it being in a SEQ? I have the following:

    WHILE TRUE
      ...
      PAR
        SEQ
          ...
        SEQ
          ...
        SEQ
          ALT
            over channel 1
              ...
            over channel 2
              ...
      ...

I can think of how to stick the ALT into a loop and yet read over both channels until both actions from the channels are complete.

Answer 83:

I'm afraid I don't understand the questions. An ALT construct can occur anywhere any other occam statement can occur - on its own, as part of a SEQ, as part of a PAR, as part of an IF etc.

Your code fragment above is illegal because there are three processes in the body of the WHILE-loop (the first set of dots, the PAR, and the last set of dots) that are all at the same level of indentation but have no controlling SEQ or PAR.

Should your "can" in your second question have been "can't"? Servicing multiple input channels is one of the basic capabilities of an ALT. Each ALT waits for and services just one input completely. Put it in a loop to service them all continuously.

Keywords: alternation , sequential-execution


Question 84:

Not really an anonymous question, more an anonymous suggestion!!

I downloaded the answers directory last night to run the example animations at home. Its only after I rebooted to Linux and tried to run it that I realised that the compiled versions are in SPARC format!! My solution - reboot to Windows telnet in, run the animations, make notes, reboot to Linux and do my assignment!

Would it be possible to put up Linux versions of the compiled code when you aren't providing the original source (in the case of assignments before the deadline)?

I know it won't help anyone in our year anymore, but it might help students in the future.

Answer 84:

The fun ones are there! Once you have built the KRoC/Linux release, look in:

    course/answers/

and you will find Linux/PC executables q7-nick and q7-fred. What we didn't include, sadly, was a Linux/PC executable for the minimal solution - i.e. the equivalent to a7 on raptor. Yes, we will do that in future. Apologies.

Keywords: demos , model-answers , linux


Question 85:

I have expanded my dining philosophers animation network like this:

  [5]CHAN OF PHILOSOPHER a:
  [5]CHAN OF FORK b:
  PAR
    secure.college (a, b)
    display (a, b, screen)

but the compiler is telling me:

    Aliasing error, 'screen' is a free variable.

Any thoughts?

Answer 85:

Yes. It must be the case that your display process does not name its third parameter screen, but nevertheless outputs to a channel called screen. Something like:

  PROC display ([5]CHAN OF PHILOSOPHER from.phil,
                [5]CHAN OF FORK b,
                CHAN OF BYTE out)
    ...  and in here outputs to the 'screen' channel instead of 'out'
  :

Now, this PROC compiles because screen is a globally visibly channel carrying the right protocol (BYTE). It must also be the case that that channel exists because you have declared display inside the body of your main q7 process, where screen is declared as a parameter. [If it had been declared on its own before your main q7 process, it would not have compiled - complaining instead about the unknown channel called screen, which would have been nice.]

Assuming the above, when the compiler came to the attempted instance:

    display (a, b, screen)

it would see an attempt to associate the real channel screen with the formal parameter out. But the compiler knows that your display outputs to this screen directly - so that the process would have two names for the same channel: out and screen. occam does not allow such aliases to happen - hence the error message.

Keywords: q7 , free-variable


Question 86:

In a replicated ALT over an array of channels, how do you include a SKIP process to deal with when none of the channels is sending data? For example:

    forks[f] ? CASE
      upfork
        SEQ
          ...  display an fork in the up position
      downfork
        SEQ
          ...  display an fork in the down position
      -- needs a SKIP if none of the forks positions have changed...

I think my program is deadlocking because it keeps waiting for forks to report when none of them have changed position.

Answer 86:

You should not need such a SKIP guard. The best thing for your display process to do when nothing is being reporting is nothing, which is what will happen if you just listen to all the report channels with a replicated ALT. If your program is deadlocking, it is for another reason - such as your college processes (philosophers, forks and security guard) outputting to parameter channels that are not correctly wired to the input channels of your display process.

If you really need to poll all those report channels (and you don't - honest), you could write something like this:

    WHILE TRUE
      PRI ALT
        ALT p = 0 FOR n.phils
          phils[p] ? CASE
            ...  deal with philosopher reports
        ALT f = 0 FOR n.forks
          forks[f] ? CASE
            ...  deal with fork reports
        INT n.sat.down:
        security ? n.sat.down
          ...  deal with this report from the security guard
        TRUE & SKIP
          ...  no reports available - do something else (like SKIP :-()

Keywords: q7 , alternation


Question 87:

The following code:

  PROC displaying ([]CHAN OF DISPLAY d, ...)
    WHILE TRUE
      ALT i = 0 FOR 6
        d[i] ? CASE
          thinking
            out.string ("Philosopher is thinking", 25, out)
          hungry
            out.string ("Philosopher is hungry", 25, out)
          ...  etc.

keeps giving me the error:

    Not enough items in i/o list.

Why does it do that?

Answer 87:

Because there are not enough items in your i/o list. Your DISPLAY protocol must contain variants that contain something other than just a tag name - maybe:

  PROTOCOL DISPLAY
    CASE
      thinking; INT
      hungry; INT
      ...  etc.
  :

In which case, your CASE input must provide the necessary variables for the relevant variant lines. For example:

        d[i] ? CASE
          INT id:
          thinking; id
            ...  make the report
          INT id:
          hungry; id
            ...  make the report
          ...  etc.

Keywords: q7 , protocol


Question 88:

Hi - I am confused about this declaration on slide 6-62

    fork (left[i], right[(i+1)\5])

What does the "\5" do and why is it not just "5" as in "left[i]"?

Answer 88:

The "\5" means "modulo 5" - i.e. the integer remainder when you divide the LHS operand, (i+1) by 5.

Your second question makes no sense - did you mean "i" as in "left[i]"? If so, look at the network diagram on slide 6-61. Each philosopher connects to left and right channels with the same index number. The forks connect to left and right channels with different indices. In most, the right channel index is one more than the left one. The exception is the fork in the top-left corner, whose right channel index is zero and has to be zero to complete the circle. The simplest way to express this is the line quoted above.

Keywords: modulo


Question 89:

When drawing the network diagram, do we have to show it as all the philosophers sitting round the table, with the all forks and all the channels - i.e. from the college perspective? Or do we have to draw it as the code we have written - i.e. 1 philosopher, 1 fork, security guard and display taking in channels from those 3 objects?

Answer 89:

For each process implemented as a network of processes, you must draw that network showing all connections - i.e. all internal processes, how they are wired together and/or wired to the outside world. If your network topology for the college reflects the college geopgraphy (e.g. philosophers and forks arranged round a table), that's a nice bonus but not essential.

There will be at least two layers of network to draw - the (secure) college network and the q7 network, consisting of the college and display processes. Each network should be drawn separately - do not try to combine two layers of network on one diagram. Ideally, you should also draw individual process icons for each process (e.g. philosopher, fork, security guard, secure college and display) that shows the shape you are using for that process and its external wires (labelled with the relevant formal parameter names used in your code). All wires should be arrowed to show the direction of data flow and labelled with the channel names used in your program. All processes should be labelled with the process names used in your program (plus any non-channel formal parameters).

Keywords: q7 , diagrams


Question 90:

Just a small point - I have tried to remove the cursor from the screen using cursor.invisible (out). However, this would apear to do nothing and my dislplay still has a big black cursor jumping all over the place?

Answer 90:

I'm afraid we are at the mercy of the completeness of the VT100 terminal emulation provided by the system we are using to get a text window. Most do not implement this make cursor invisible function and there's nothing we can do about it (apart from hacking the source code of the terminal emulator if we can get hold of it). In the good old days, we used to have real VT220 (which superceded VT100) terminals and this cursor.invisible procedure worked just fine!

Keywords: animation , cursor.invisible


Question 91:

A friend told me that I should be using:

    out ! FLUSH

after every single output. My program works perfectly well without them. Do I need to include them for safety?

Answer 91:

Not for safety reasons. Unix flushes characters written to its standard output whenever the associated memory buffer gets full or when it gets a new line character. In addition, KRoC forces Unix to flush its buffer when the FLUSH character is sent.

You should flush your animation output after each completed update of the screen (but not, of course, after each character). If you did not and action was progressing slowly in your animation, you would not see anything until the Unix buffer became full when, suddenly, you would see everything that had happened since the last time the buffer was flushed. This is because individual animation updates would not usually include a new line character. If your animation is very active, you will be continually filling the Unix buffer and, so, would see things happening suddenly in bursts (as a full buffer is flushed), separated by periods in which nothing seems to happen (as the buffer is being filled).

However, if your animation is very active but includes a user freeze command and you haven't sent a FLUSH, the animation would freeze but you would not see the latest updates. Of course, you could respond to a freeze by sending a FLUSH ...

But if there are other ways of interacting with the animation (see a7-1997 and a7-1998 in the answers directory on raptor), you will need those FLUSHes. Otherwise you may run into latency problems: what you see on the screen might be the state of the animation a while back - the latest updates are buffered up somewhere and have not been sent to your screen yet!

Keywords: flush , animation

Referrers: Question 33 (2010) , Question 37 (2009) , Question 51 (2004) , Question 114 (2003)


Question 92:

I am doing my own implementation of the q7 (i.e not using any of the methods part written). I won't be docked marks because of this (presuming that my implementation is correct)?

Answer 92:

No - that's perfectly in order.

Keywords: q7


Question 93:

Can you tell me how the CO516 exam is split between the parallel and imperative components of the course? In other words, is section A on C programming and section B on occam?

Answer 93:

Yes. Section A has 2 questions on C, while section B has 4 questions on occam (+ a little JCSP).

Keywords: exams


Question 94:

Re. the 2000 exam paper question 6(h). Have we covered the double buffering required to prevent the breaking of parallel usage rules with Java objects? If you could point me in the right direction, it'd be appreciated.

Answer 94:

Double buffering is a simple idea. The sender process declares two objects of the type that it's going to output - these are the "buffers". In each loop, it sets up one of them and sends it. It switches between which object to use after each loop - the first loop it uses object 1, the second loop it uses object 2, the third loop it uses object 1 again, the fourth time it uses object 2 again etc.

The receiving process need not be aware of these switches. In each cycle, it just inputs an object, processes it and forgets about it. [For example, the B process of part (g) needs no change.]

Now, when the sender is working on obect 2, the receiver will be working on object 1 - and vice-versa. Each process is always working on different objects and there is no race hazard. The switching between which object to use is synchronised by the (once-per-cycle) channel communication.

That's all there is to it. For information on its use in anger, see the (javadoc) documentation on:

  jcsp.plugNplay.ints.ParaplexInt

and:

  jcsp.lang.parallel  (the "High Level" and "Low Level" examples)

Keywords: double-buffering , jcsp

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