XML

kent logo

CO538 Anonymous Questions and Answers Keyword Index

This page provides a keyword index to questions and answers. Clicking on a keyword will take you to a page containing all questions and answers for that keyword, grouped by year.

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.

Keyword reference for race-hazard

2003

Question 120 (2003):

In the question from the 2000 exam paper below what would be the correct answer to what's written below. I know it's because of race hazards it is illegal, but I can't think of a way to rewrite the code.

Consider the following (illegal) outline of an occam system:

    BOOL running:
    SEQ
      running := TRUE
      PAR
        WHILE running
          ... do operation A
        SEQ
          ... do operation B
          running := FALSE

what was the the system trying to acheive? modify the code so it acheives it legally

Answer 120:

The solution is to use a channel and communication. The 2nd parallel process is easy -- change the assignment to a channel output. Modifying the 1st parallel process is less obvious. Essentially it's a ``check if still `running', and if so, do operation A''. The `check' needs to be modified, but it can't be a simple input. Instead, an `ALT' is required, to select between `communication from the other process' and `nothing'. In code:

    BOOL running:
    SEQ
      running := TRUE

      CHAN BOOL c:
      PAR
        WHILE running
          PRI ALT
            c ? running
              SKIP
            TRUE & SKIP
              ... do operation A

        SEQ
          ... do operation B
          c ! FALSE

This is polling, that isn't a very pleasant thing to do. Depending on what `operation A' is, it might be possible to move the ALT on `c' inside.

Keywords: race-hazard , exams

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