CSE132 Midterm Exam Make-Up
Due 24 April 2009, in Cytron's Bryan 509 mailbox
Do not submit this by email!

Read these instructions carefully!

  1. Model/view/controller: to make up points on this, implement the Die class in eclipse and submit your code and some screenshots showing how it works.
    Make sure that your code follows the model/view/controller pattern. Ask me questions if you are unsure how to proceed.
  2. I suspect that this question will attract the most attention. To make this up, take a look at the BlockingQueue object you implemented in Studio 9. I ask you to submit a thorough discussion that addresses the following questions and issues:
    1. What is the proper form for writing concurrency-based code that waits for a condition p to become true?
      Be sure to address both the wait and the notifyAll sides of this issue.
    2. In the BlockingQueue, consider the following wait() and notifyAll() calls that could be placed in your code. A given call (i.e., this.wait() would appear everywhere a wait is needed; same story with a given notifyAll call.

      For each pair of calls, discuss why the pair would or would not work correctly for BlockingQueue. Your answer must be thorough and complete, but not necessarily long. You must identify all of the problems with a given pair, or show convincingly why you know the pair would work.

      • wait() and notifyAll()
      • this.wait() and this.notifyAll()
      • queue.wait() and queue.notifyAll()
      • this.wait() and queue.notifyAll()
      • this.getClass().wait() and this.getClass().notifyAll()
      • new Integer(131).wait() and new Integer(131).notifyAll()
  3. For this midterm question, I ask that you consider the following situations. For each, submit a discussion of how your answer on the midterm relates to the situation and what exactly would happen in the situation given your answer.
    If your midterm answer was insufficiently complete to do this without making new stuff up, please just say so, and then propose a new answer to the midterm question. You can then use that new answer to discuss the situations.

    Your response to the situations depends on your answer to both questions that were posed on the midterm. Be sure to propose one approach for having customers deal with their tickets, and answer the questions below consistently based on that approach.

    If deadlock can happen, that's fine, but state convincingly why that is the case. If deadlock cannot happen, provide a reasonable explanation of what prevents deadlock.

    • Customer A has ticket 4 for the deli and ticket 5 for the bakery. Meanwhile, Customer B has ticket 4 for the bakery and ticket 5 for the deli. Both Customers are single threaded. Customer A calls invokeWhenMyTurn on A's bakery ticket, and Customer B calls invokeWhenMyTurn on B's deli ticket.
    • A customer has a Ticket for each of the three TMs in a store. How does your approach allow the customer to respond to whichever ticket is called next?