Exercises


  • 5.1 A single-slot buffer may be modeled by:

     ONEBUF = (put->get->ONEBUF).

  • Program a Java class, OneBuf, that implements this one-slot buffer as a monitor.

  • 5.2 Replace the condition synchronization in your implementation of the one-slot buffer by using semaphores. Given that Java defines assignment to scalar types (with the exception of long and double) and reference types to be atomic, does your revised implementation require the use of the monitor’s mutual exclusion lock?

  • 5.3 In the museum example (Chapter 3, exercise 3.6), identify which of the processes, EAST, WEST, CONTROL and DIRECTOR, should be threads and which should be monitors. Provide an implementation of the monitors.

  • 5.4 The Dining Savages: A tribe of savages eats communal dinners from a large pot that can hold M servings of stewed missionary. When a savage wants to eat, he helps himself from the pot unless it is empty in which case he waits for the pot to be filled. If the pot is empty, the cook refills the pot with M servings. The behavior of the savages and the cook is described by:

     SAVAGE = (getserving -> SAVAGE). COOK   = (fillpot -> COOK).

  • Model the behavior of the pot as an FSP process and then implement it as a Java monitor.

  • 5.5 FSP allows multiple processes to synchronize on a single action. A set of processes with the action sync in their alphabets must all perform this action before any of them can proceed. Implement a monitor called Barrier in Java with a sync method that ensures that all of N threads must call sync before any of them can proceed.

  • 5.6 The Savings Account Problem: A savings account is shared by several people. Each person may deposit or withdraw funds from the account subject to the constraint that the balance of the account must never become negative. Develop a model for the problem and from the model derive a Java implementation of a monitor for the savings account.




Concurrency(c) State Models & Java Programs
Concurrency: State Models and Java Programs
ISBN: 0470093552
EAN: 2147483647
Year: 2004
Pages: 162

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net