3SFE605 Concurrent Programming 2009
3SFE605 Concurrent Programming 2009
Instructions to Candidates:
Answer THREE questions.
Each question is worth 33 marks.
c University of Westminster 2009
MODULE CODE: 3SFE605 Page 1 of 8
MODULE TITLE: Concurrent Programming
Question 1
(b) Figure 1 represents the un-labelled states (nodes) and transitions (arcs) of
the life-cycle of a Java thread.
b o
c n
e m
h j
g k
f i l
(c) Within the Java Virtual Machine (JVM) threads use low-level actions to
interact with the main memory, i.e., transferring values of variables between
the main memory, the thread’s working copy and the thread’s execution
engine. Describe these low-level actions. [9 marks]
c University of Westminster 2009
MODULE CODE: 3SFE605 Page 2 of 8
MODULE TITLE: Concurrent Programming
Question 2
(i) Describe in detail the sequence of states of the object mb and the
threads p and r during its execution; assuming that r calls mb’s
retrieve() method before p calls its post() method. [6 marks]
(ii) If the MessageSystem class created several Poster threads and
several Retriever threads rather than just one of each, deadlock
could occur.
Assuming deadlock has occurred, explain what has happened to the
Poster and Retriever threads. What is the simplest change that
could be made to the two MessageBoard methods post() and
retrieve() that would stop this happening. [5 marks]
c University of Westminster 2009
MODULE CODE: 3SFE605 Page 3 of 8
MODULE TITLE: Concurrent Programming
Question 3
(a) Explain the concept of a design pattern. How do design patterns assist in
developing concurrent object-oriented programs? [7 marks]
(c) Describe the overall approach of the Immutability design pattern, and
the six design steps that are used when applying the Immutability design
pattern to develop a class. [7 marks]
(d) Apply the Immutability design pattern to produce a Java class called
Personal_ID, that can be used to represent a person’s identity using their
name and date of birth. Examples of possible values for each of these at-
tributes, using the Java String type, are "Jim Jones" and "21/3/1970".
In addition it should have accessors for each attribute called name and dob.
[9 marks]
c University of Westminster 2009
MODULE CODE: 3SFE605 Page 4 of 8
MODULE TITLE: Concurrent Programming
Question 4
(b) Many design patterns for achieving liveness are based on the technique
known as “splitting synchronization”. One technique for doing this is
known as lock splitting, describe this approach. [7 marks]
(c) The Java Rectangle class is given in Appendix B. This class provides the
basis for displaying (i.e., moving and resizing) rectangular shapes, that for
example, could be used to implement terminal windows.
You can assume that moveRectangle() never deals with its dimensions
and resizeRectangle() never deals with its location.
The Rectangle class is seen as inefficient, i.e., has poor liveness charac-
teristics.
c University of Westminster 2009
MODULE CODE: 3SFE605 Page 5 of 8
MODULE TITLE: Concurrent Programming
Question 5
(d) Using your Semaphore class, write a Java program for the Dining Philoso-
phers problem which avoids deadlock by using a Butler.
Describe how your Semaphore class can be used to model parts of the
program.
You must provide a Philosopher class, which represents the behaviour of
a philosopher and a DiningPhilosopher class which creates the philoso-
phers, forks and butler.
Note: assume that all threads will execute forever. [12 marks]
c University of Westminster 2009
MODULE CODE: 3SFE605 Page 6 of 8
MODULE TITLE: Concurrent Programming
Appendix A
Program for Question 2: comprises four classes Poster, Retriever,
MessageBoard and MessageSystem.
message = messageboard.retrieve();
message = messageboard.retrieve();
}
}
[Continued Overleaf]
c University of Westminster 2009
MODULE CODE: 3SFE605 Page 7 of 8
MODULE TITLE: Concurrent Programming
class MessageBoard
{
private Object message = null;
private boolean message_posted = false;
class MessageSystem
{
public static void main(String args[]) {
MessageBoard mb = new MessageBoard() ;
Poster p = new Poster(mb) ;
Retriever r = new Retriever(mb) ;
p.start();
r.start();
}
}
c University of Westminster 2009
MODULE CODE: 3SFE605 Page 8 of 8
MODULE TITLE: Concurrent Programming
Appendix B
Program Code for Question 3: consisting of the Rectangle class.
c University of Westminster 2009