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:

Submission reference: IN1916

Will we lose marks by not including ASCII data-flow diagrams after adding freeze and speed.control components?

Answer 21:

Nope! We should have asked you to include network diagrams in some form (ASCII art, hand drawn on paper, electronic media) ... but we didn't, :(.

I'm sure you did draw some diagrams anyway – it's very difficult to know what you are doing if you don't!

Keywords: q4


Question 22:

Submission reference: IN1917

Hey, I have a couple of questions regarding Q7. is it possible to concatenate a variable within a string? So instead of using:

  SEQ
    out.string ("phil no: ", 0, out!)
    out.int (i, 0, out!)

you could have something like:

  out.string ("phil no: " + i, 0, out!)

Also, can deadlock be caused by not flushing the screen in the correct place? Or by something similar as I currently have the following inside my display PROC:

  ...  code omitted

and this currently gives the output:

    philosopher number: 0 is 0
    philosopher number: 1 is 0
    philosopher number: 2 is 0
    philosopher number: 3 is 0
    philosopher number: 4 is 0
    philosopher number: 0 is 1
    philosopher number: 0 is 2
    philosopher number: 0 is 3

before deadlocking.

Answer 22:

To allow:

  out.string ("phil no: " + i, 0, out!)

we need an operator, "+", between a string of arbitrary length (left operand) and an INT (right operand) giving a string result. Arbitrary length strings can be defined as MOBILE arrays (see slides 2-19 on "mobiles", especially slide 14). New operators, beyond those built into the language, can be user-defined. They are side-effect free (just like FUNCTIONs) and are defined using (almost exactly) the same syntax as FUNCTIONs. Sorry, there are currently no notes/slides on this, but they are described, with lots of examples, on this web page and in this paper.

So, sorry! Without arbitrary length strings and user-defined operators, we can't do what you want – we have to output strings and integers separately using separate procedures (e.g. out.string and out.int).

Re. your second question: no, sending a FLUSH to the screen should have no impact on dealock issues. FLUSH is just another BYTE, so sending it has no special synchronisation meaning in occam semantics. Your code outputs several lines before sending just one FLUSH. That is fine! Your output looks wrong (?) but your FLUSH is not the cause of your deadlock.

Keywords: q7


Question 23:

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


Question 24:

Submission reference: IN1919

Hey, Is it possible to use an input channel as a guard if its type is a CASE protocol? It doesn't seem to allow me to declare variables of type CHOICES which is understandable but I can't work out how else I can PRI ALT over one channel containing the reports and another input channel that takes in commands. I'm basically trying to implement pause functionality but it seems I can only get this to work if I use an extended rendevous within the display process (I want all processes that output onto the shared CHOICES channel to halt execution until the indented code is executed). Maybe there's a better approach?

Incidientally if I'm unable to get this implemented, would it have much affect on my mark? I plan on doing parallel philosopher animations where you can change the speed at which the philosophers move but I need some help from my seminar leader before I start implementing this.

Answer 24:

Yes. Any channel, carrying any kind of protocol, can be used as an input guard in an ALT (or PRI ALT).

I'm guessing your CHOICES is a (CASE) PROTOCOL you have declared? If so, you can't declare variables with 'type' CHOICES:

  CHOICES x:     -- will not compile

A message protocol is carried by channels – it's not a type with which variables can be declared. To input from a CASE protocol, we don't write:

  in ? x

Instead, there is a special syntax – see slide 70 of the "protocol" slides. Then, you will be able to ALT between channels carrying reports and another carrying commands.

There won't be too many marks for implementing a pause – it's very simple, if you do it right ... ;)

Keywords: q7


Question 25:

Submission reference: IN1920

I'm trying to achieve parallel animation but now that I have various animation processes the location of characters on the screen has gone crazy. For example philosophers and forks turn up where the number seated should be displayed. I'm guessing this is because my third parameter for cursor.x.y is the connection between the respective animation process and the display process. Does it need to directly link to the screen to work properly? My code works fine if I do all the animation stuff within the display process and I'm CLAIMing the channel before output so I can't see what else could be the problem.

Answer 25:

The third argument to cursor.x.y could be any channel carrying BYTEs. Normally, this would be the screen channel but it doesn't have to be (but, in that case, the BYTEs would need to be forwarded eventually to the screen channel to be seen). Care would have to be taken to keep sequences together that need to be kept together (e.g. screen control sequences and the text they are placing!).

It sounds like you are not doing this with enough control? If you have parallel animation processes writing to the same SHARED channel, the channel must be claimed for the whole of each individual animation movement. For example, don't do this:

  SEQ
    CLAIM to.screen!
      cursor.x.y (x, y, screen!)
    CLAIM to.screen!
      out.string ("  ", 0, screen!)
    CLAIM to.screen!
      cursor.x.y (x+1, y, screen!)
    CLAIM to.screen!
      out.string (":)", 0, screen!)!)
    CLAIM to.screen!
      to.screen ! FLUSH

because other process can interleave their CLAIMs in between the above ones, with resulting chaos like you described. Instead, do this:

  CLAIM to.screen!
    SEQ
      cursor.x.y (x, y, screen!)
      out.string ("  ", 0, screen!)
      cursor.x.y (x+1, y, screen!)
      out.string (":)", 0, screen!)
      to.screen ! FLUSH

Now, the cursor control sequences and associated texts will stay together. This process has exclusive use of the claimed channel throughout the CLAIM.

Keywords: q7

Referrers: Question 33 (2010)


Question 26:

Submission reference: IN1921

Is there any way of elsing on the guards of an ALT statement – i.e. if a guard blocks it, do something else. I only ask because I want to see if the security blocks a philosopher when it tries to sit down.

Answer 26:

Yes – use a SKIP guard at the end of a PRI ALT. See slide 30 of the "choice" slides.

Keywords: alt


Question 27:

Submission reference: IN1923

Hi there, I've a little timing problem on the q7

  phil.0:MAY I SEAT DOWN? 
  phil.0:I'M SITTING
  security:SEAT NUMBER 0. PHILOSOPHERS AT THE TABLE 2

Is that normal? Do I have to put some delays on the philosophers process?

Answer 27:

It looks like your philosopher process reports the first line (of your above messages), then communicates with security, then reports the second line. And your security process reports the third line when it gets the communication (I just assumed) from a philosopher.

If so, after the communication between the philosopher and security, both processes continue in parallel and try to report their states (the second and third lines). Of course, those reports (and, hence, lines) may appear in either order.

If we need to control the order (e.g. so that the security guard makes its report first), we don't do it by putting in delays! The scheduling would then become dependent on the length of the delays. If this were a real-time control system, many changes in the coding and the platform processors will happen over its lifetime maintenance ... and timing figures that were once correct can become incorrect.

Instead, control the order by putting the control in the logic of the code. For example, if the security process were to accept the philosopher request (to sit down) with an extended input and make its report in the extended rendezvous, that report would be complete before the philosopher became aware that its request had been taken – so the philosopher's report would be bound to follow that from security. No delays are needed to manage the scheduling, :).

Keywords: q7

Referrers: Question 28 (2012)


Question 28:

Submission reference: IN1926

I've been cracking my head on this prob for the last few days but still can't find a solution.. the program keeps deadlocking for some reason.. I think its some prob with the display process, but can't figure out exactly what.. cheers for any help..

  -- [snip code]

  PROC secure.college ([]CHAN STUFF outs!)
    --{{{  
    [n.philosophers]CHAN BOOL left, right, up, down:
    [11]CHAN STUFF out:
    SEQ
      PAR
        PAR i = 0 FOR n.philosophers
   PAR
     philosopher (i, left[i]!, right[i]!, down[i]!, up[i]!,out[i]!)
     fork (right[i]?, left[(i+1)\n.philosophers]?, out[i+5]!)
        security (down?, up?, out[10]!)
    --}}}
  :

Answer 28:

The problem lies in your "secure.college" process. The process header specifies an array out output channels ("outs"), which are ultimately connected to the "display" process. However, within that PROC you declare another array of channels ("out"), and then plug that into the various sub-processes! The effect is that when any of these tries to output to its reporting channel, it'll immediately deadlock, since there is no process connected to the input ends of the "out" channel. In effect, remove the "out" declaration, and wire in the "outs" channels instead.

Keywords: q7


Question 29:

Submission reference: IN1925

I'm currently working on the dining philosophers animation but for some reason after making some changes my code refuses to compile - It doesn't produce any error messages but actually seems to break the compiler, giving me the following output:

  Compiling: q7.occ
  skroc: Could not compile q7.occ.
  skroc exited with error code: 1

I've tried the same code on two different machines with two different transterpreter versions (my laptop is running the latest one from the website) and get the same result.

I've tried undoing what I changed to cause such an issue but it doesn't seem to have helped. I appreciate that debugging this may well be impossible without seeing the source code, but I hoped you might be able to suggest what I could possibly have done to cause this.

Thanks!

Answer 29:

Without any more error messages it's a pretty hard problem to diagnose. Although it seems like a daft suggestion, check that the "q7.occ" file it's trying to compile actually exists and is readable, and/or, that the directory it's in is writable. It might also be the case that the "skroc" command cannot find the compiler executable, but if that were the case, I'd expect a more detailed error message (or at least some hint). It may be worth checking the occplug settings to make sure these are sensible (and that the paths referred to exist and contain the expected files). If you still have problems, post again, but please also say what OS you're using and what version of the Transterpreter.

Added later: one of the Transterpreter developers has just mailed:

Given that it mentions skroc in the output it must be a very old version of something. Try to get the student to upgrade?

Are you sure you are using the latest version from the website? What is its version number? You can ask again anonymously ... but it's faster to mail us (phw@kent.ac.uk, frmb@kent.ac.uk).

Keywords: q7 , transterpreter


Question 30:

Submission reference: IN1927

Is it possible to declare an array of SHARED channels? "SHARED ! [n]CHAN BOOL lol" gives an error message.

Answer 30:

Nope, unfortunately that will not work; you'll need to declare them individually. This will be fixed in a future version of a compiler.

Keywords: q7 , shared-channel

Referrers: Question 34 (2011)


Question 31:

Submission reference: IN1924

Why is it that after closing down the graphics panel that opens up once mars.occ is run, the transterpreter encounters a STOP run-time error forever after?

I have to delete the files and unzip them again just to be able to re-run the program. This happens when either closing the simulation or pressing the stop button JEdit.

I have downloaded the more recent TVM.

Answer 31:

There seems to be a bug with our code that writes out the "background.ppm" file, once it's been computed. Given that the starter zip file includes this file, your program doesn't have to make it. So, the work-around to our bug is not to make that file. To do this, comment out line 10 of the file "mars-sim.occ" – i.e.

  --#DEFINE GENERATE.BACKGROUND

The starter zip file has now been updated with the above work-around.

Keywords: mars

Referrers: Question 32 (2010) , Question 39 (2010) , Question 39 (2010)


Question 32:

Submission reference: IN1922

Hey, I have a few questions related to the life on Mars assessment. Should each task be implemented in a PROC and then wired up in PROC robot.control.

Also I had the error:

    exiting... (unimplemented instruction)
    The error occurred on or around line 91 in cordic.occ
    mars.tbc exited with error code: 999

That was described on the web page linked from moodle, I have followed the directions to fix this but I am now receiving another error that says:

    The transterpreter has encountered a runtime error:
    STOP error
    The error occurred on or around line 29 in ppmwrite.occ
    mars.tbc exited with error code: 10

Any idea on what im doing wrong or how to fix it? Thanks.

Answer 32:

Task items 1 and 2 could be answered in-line – i.e. without abstracting the code into a separate procedure (PROC). However, items 3 and 4 require the robot to perform more than one turn and/or move, so having procedures for moving and turning would be very helpful here. The trick is to define sufficiently general abstractions (i.e. parameter list and parameter list meaning) so that they are easy to use when doing items 3 and 4. The simple way to test these abstractions is, of course, to use them for items 1 and 2, which also yields a more elegant solution.

The PROCs suggested in the previous paragraph would be used in SEQuence with other code. You may want to define and run other PROCs in PARarallel - so that, for example, messages arriving from the motors, camera or hazard detectors are always accepted and saved (perhaps in a one-place overwriting buffer?) ... so that the latest (and not stale) reports are always available to the robot control process. But you could do this instead by ALTing on all those motor/camera/hazard channels whenever you need input from any one of them.

Re. your other problem with runtime error from the transterpreter, see Question 31 (2010). If that doesn't fix it, let us know again – thanks.

Keywords: mars

Referrers: Question 39 (2010) , Question 40 (2010) , Question 42 (2010)


Question 33:

Submission reference: IN1930

Hi, I'm doing the dining philosophers animation (q7.occ) and the animation loads but it either runs excruciatingly slowly (as in takes minutes to show anything in the terminal) or it just gives me a blank screen.

I know it isn't the Transterpreter or the computer I'm using because the display process ran at the right speed when it was just printing out lines of text. I also doubt if it is to do with the implementation of my random and seed functionality because again this worked with the scrolling text.

Any help would be greatly appreciated!

Answer 33:

Changing to animated output, from lines-of-text output, won't have any noticeable change in the rate at which your program is generating output.

I suspect that you are failing to send a FLUSH to the screen after completing each change on the screen you want to show? When you were sending lines of text, the newline character at the end of each line automatically flushed out the preceding line to the screen. Your animation update bytes probably do not end with a newline – if so, nothing will appear on your screen until the screen output buffer (part of the OS support, not your occam system) becomes full. In that case, you will see nothing for a while ... then, all of a sudden, all your screen animation comes out so fast you don't see most of it ... then nothing for a while ... etc. See Question 91 (2000).

If this is your problem, it's easily fixed – for examples, see Question 25 (2010) and Question 49 (2009). If not, mail me (p.h.welch@kent.ac.uk).

Keywords: q7

Referrers: Question 34 (2010)


Question 34:

Submission reference: IN1931

Hi, I'm still working on the dining-philosophers (q7) assessment and am having real trouble with my animation.

For some reason the terminal takes minutes to display anything, and when it does display something, it takes minutes more before it changes again in response to incoming reports.

I don't know what it is but I'm pretty sure it's not due to my random implementation or my Transterpreter version /computer, as the display process worked when all it had to do was output lines of text.

Any help would be greatly appreciated! Unbelievably confused right now...

Answer 34:

I think this is the same as Question 33 (2010) ...

Keywords: q7


Question 35:

Submission reference: IN1929

For the Mars Rover assignment it mentions in "Starting out on Mars" page that we should consider using the IABS function. Will we lose any marks for not using it?

Answer 35:

No – you won't lose marks for not using it ... but using it may help you write simpler code.

The IABS function takes an integer argument and returns it without any minus sign (if present). So, for example, IABS(21) returns 21 and IABS(-21) returns 21. The function is trivial and declared in the file mars-robot.inc.

Keywords: mars


Question 36:

Submission reference: IN1928

Hi. I don't know how to use shared channels to send information to the philosophers on the display. They all are running on parallel, if I use shared channels and have to send some information to just one of the philosophers, I have to include in the philosopher's code a condition, like:

  PROC philosopher (VAL INT me, SHARED CHAN ACTIONS display?, ...)
    INT phil.number, x,y:
    WHILE (TRUE)
      SEQ
        display ? CASE move.philosopher; phil.number;x;y
        IF 
          me = phil.number
            ...

In the sender code there would be something like:

      display ! move.philosopher; phil.number; x;y;

But if I use array channels, I just send the information I want to the concrete phil.number:

  PROC philosopher (VAL INT me, CHAN ACTIONS display?, ...)
    INT phil.number, x,y, message:
    WHILE (TRUE)
      SEQ
        display ? x;y; message
          CASE message
            MOVE
              ...

In the sender code there would be something like:

      display[phil.number] ! x;y; MOVE

With arrays channels I get parallel movements, but not with shared channels. What would be the right way to use shared channels in this case?

Answer 36:

Sorry – I don't understand: "send information to the philosophers on the display"? Your (first piece of) code has the philosopher process inputting messages (ACTIONS) from a display. What are these actions? The "x;y" elements hint that they are coordinates on the screen where you want an icon, representing this philosopher, placed. But ... if so, should this not be a message output by the philospher to the display?

However, if you really want to "send information to the philosophers" (for example, control information to change its delay periods), you cannot use a channel whose input-end is shared by all the philosophers for this. Channels with shared input-ends do not broadcast messages to all receiving processes (which looks like what your code is anticipating). Channels with shared input-ends still carry only point-to-point messages – with receiving ends queueing to be the next receiver (which is enforced by a CLAIM on the shared channel input-end ... that's missing from your code fragment).

As you later note, to "send information to the philosophers", an array of separate channels is needed.

As you also note, the way to get parallel movements (i.e. more than one icon moving at a time) is to output from the icon-representing processes (i.e. phils, forks and security guard) down parallel channels (i.e. elements from an array). The phil/fork/security processes do not need changing from the ones that drove the scrolling lines of text version - other than not using a SHARED report channel, but an array instead. Receiving each report channel can be an animation process that's responsible for remembering where its icon is on the screen and moving it ... by sending messages down a shared channel to a simple display process (that's responsible for simple things like: output this string of characters at these coordinates on the screen).

I do remain fairly confused by your question though. I hope this helps!

Keywords: q7


Question 37:

Submission reference: IN1932

Hi there, I'm having a bit of trouble with q7. I've created all my protocols, wired up all the SHARED channels, and created my display process with the CASE statement to spit out the status of the philosophers ...

My program deadlocks when the last philosopher wants to sit down. The problem is that the security process does not manage to get to:

    n.sat.down := n.sat.down - 1

for some strange reason ... and so no philosopher ever stands up.

I know it's probably pretty difficult to diagnose the problem without pasting code ... but any idea why this would happen?

Thanks.

Answer 37:

You're right – it's really not possible to explain your deadlock from the information you have given. :(.

I assume your security process is reporting the number of phils it has let into the dining room whenever this changes? And that is why you know the security guard never counts down? If not, do that.

Check that the eating periods you set for the phils is not very large – that they have the order of seconds (i.e. millions of the microsecs that TIMERs tick to) and not minutes (i.e. hundreds of millions).

Otherwise, nothing springs to mind, I'm afraid. If still stuck, read each of your processes carefully. Ask yourself why should it work – justify this to yourself, as if reading the process for the first time and that someone else has written it. Don't ask why doesn't it work – that encourages you to continue to overlook the mistake you made before (over which you now have a blind spot)! If still stuck, contact your seminar leader ... or me (p.h.welch@kent.ac.uk).

Keywords: q7

Referrers: Question 43 (2010)


Question 38:

Submission reference: IN1933

Hi my program deadlocks ... for some reason when I have VAL INT n.philosophers IS 2: my sequence goes like this:

  philosopher 0 thinking
  philosopher 1 thinking
  philosopher 0 hungry
  philosopher 1 hungry
  philosopher 0 sitting
  philosopher 1 sitting
  philosopher 0 sitting
  total philosophers = 1
  philosopher 0 holding left fork
  philosopher 0 holding right fork
  fork 1 up
  fork 0 up
  philosopher 0 eating
  philosopher 0 put left fork down
  fork 0 down
  philosopher 0 put right fork down

... then deadlock ...

any idea why that might be happening? thanks in advance

Answer 38:

Without seeing the code, it's hard to diagnose. I'd suggest mailing your code to your seminar leader and asking for some pointers as to where things are wrong.

Keywords: q7


Question 39:

Submission reference: IN1934

Hey, This is in relation to my earlier question, Question 32 (2010). After doing the steps suggested in Question 31 (2010), I now receive the following error:

  The Transterpreter encountered s runtime error:
  STOP error
  The error occurred on or around line 288 in mars-sim.occ
  mars.tbc exited with error code: 10

I have also downloaded the source again but still receive these two errors. Any idea how to fix it?

Answer 39:

Your program should not be executing line 288 of mars-sim.occ!

The only way it could do this if line 10 of mars-sim.occ has not been commented out – which the answer to Question 31 (2010) tells you to do.

Make sure you have cleared your browser's cache when looking at the Life on Mars web page. Make sure the starter code you are downloading is the latest version: life_on_mars-20101130.zip, which has been on-line since last Tuesday (30th. November). This starter code does not need any editing on the mars-sim.occ (line 10 is already commented out).

Keywords: mars


Question 40:

Submission reference: IN1935

Hi, I am currently quite stuck on the Life on Mars assessment, part 3, where you have to scan for a blob and return if you've found it.

I don't quite understand how the robot's camera is supposed to work, and looking over the mars-sim.occ file hasn't helped either.

I have two ideas on how it works, though neither really help when I try to work my code around them:

Am I missing something obvious? The lack of questions on this make me feel like I'm doing something stupid. The document isn't very clear, at least.

Answer 40:

The camera is working all the time; its images are scanned and data on blobs, if any, identified and sent towards your robot.control process every few seconds – regardless whether your process inputs them or not.

If your robot.control does not input camera data for a while, the data is likely to be stale (e.g. the bearing of the blob ... because the robot has turned since the blob was found). It may be that the image processing sub-system buffers up many stale blob findings (and may overwrite some), if your robot.control does not take them. To avoid this, your system should always be prepared to take sensor data (from its camera, hazard detectors and motor feedback) whenever they might be available. For the camera and hazard detectors, that is at all times. For the motor feedback, that is whenever the robot is moving. Your robot control should never listen solely to one sensor channel: if it does, it will have to wait for some data to arrive ... which may not be for a second or two, which is far too long to be doing nothing! See also the second paragraph in the answer to Question 32 (2010).

Hope this helps! You do not have to understand the code in mars-sim.occ (or mars-robot.inc), though you are welcome to browse!

Keywords: mars

Referrers: Question 42 (2010)

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