Docsity

Understanding Active Objects and Monitors in CSE 335, Spring 2009, Assignments of Computer Science

Toggle sidebar
bg1
H8: Active Objects and Monitors
CSE 335, Spring 2009
Due by Tuesday, April 14 at 11:59 p.m.
Objectives
1. Learn about how to synchronize threads.
2. Learn about the active object and monitor patterns (not covered in the design patterns book).
3. Gain experience drawing sequence diagrams representing multithreaded interactions.
4. Gain experience with the ACE toolkit.
Description
For this homework, you will be comprehending a multithreaded program that involves producer
and consumer threads interacting over a shared buffer. The producers and consumers produce and
consume lines of text (i.e., strings), respectively. They are implemented as active objects. The
producers pass lines to the consumers through the shared buffer, which is implemented as a monitor.
Figure 1depicts the design of the program.
The sources for this program are available in /user/cse335/S09/H8-src. For this assignment,
you will examine the program to comprehend how the producer and consumer threads use the
mechanisms that we have discussed in class (i.e., mutexes and condition variables) to synchronize.
Then, you will create a sequence diagram representing a specific scenario of interaction.
Tasks
1. Copy the files into your workspace. We will not be using svn for this assignment.
1 1
<<monitor>>
...
2 2
LineProducer LineConsumer
BoundedLineBuffer
putLine(id : int, line : string)
getLine(id : int) : string
...
Figure 1: Design of producer-consumer program.
1
pf3
pf4

Partial preview of the text

Download Understanding Active Objects and Monitors in CSE 335, Spring 2009 and more Assignments Computer Science in PDF only on Docsity!

H8: Active Objects and Monitors

CSE 335, Spring 2009

Due by Tuesday, April 14 at 11:59 p.m.

Objectives

1. Learn about how to synchronize threads.

2. Learn about the active object and monitor patterns (not covered in the design patterns book).

3. Gain experience drawing sequence diagrams representing multithreaded interactions.

4. Gain experience with the ACE toolkit.

Description

For this homework, you will be comprehending a multithreaded program that involves producer

and consumer threads interacting over a shared buffer. The producers and consumers produce and

consume lines of text (i.e., strings), respectively. They are implemented as active objects. The

producers pass lines to the consumers through the shared buffer, which is implemented as a monitor.

Figure 1 depicts the design of the program.

The sources for this program are available in /user/cse335/S09/H8-src. For this assignment,

you will examine the program to comprehend how the producer and consumer threads use the

mechanisms that we have discussed in class (i.e., mutexes and condition variables) to synchronize.

Then, you will create a sequence diagram representing a specific scenario of interaction.

Tasks

1. Copy the files into your workspace. We will not be using svn for this assignment.

<>

LineProducer LineConsumer

BoundedLineBuffer

putLine(id : int, line : string)

getLine(id : int) : string

Figure 1: Design of producer-consumer program.

  1. Examine the source code, reading the comments thoroughly. Note the interfaces of the active- object classes. Observe how the run functions implement the objects’ respective control loops and how the start functions are used with the spawn function. Finally, note the implementa- tion of the monitor class. Observe how guard objects are used to acquire/release the lock and how the waiting/signaling of condition variables is done.
  2. Build and run the producerConsumer application. Examine the output and the source code until you can explain why the output looks as it does. Run the program a few more times and note differences in the output. Find explanations for these differences.
  3. You will now draw a sequence diagram representing a thread interaction. Assume that when the interaction starts, the buffer is empty and the active objects are at the tops of their control loops. Draw a sequence diagram representing an interaction that would produce this output: PRODUCE: Producer #1 (buf.size = 1) CONSUME: Consumer #2 (buf.size = 0) WAIT-ON-EMPTY: Consumer # WAIT-ON-EMPTY: Consumer # PRODUCE: Producer #1 (buf.size = 1) CONSUME: Consumer #1 (buf.size = 0) Use the diagramming conventions discussed in lecture (see Figure 2). Make sure your di- agram represents the all the state changes associated with mutex acquires/releases and con- dition variable waits/signals. Note: There may be more than one possible interaction that produces the above output; you should just model one of them. Either draw your diagram by hand on the attached sequence diagram template, or draw it using a drawing application. If you choose to use an application, you must be able to submit your diagram as a PDF or PS file (no M$ Office formats!).
  4. Extra credit: For up to five additional homework points, draw another sequence diagram. This time assume that the buffer initially has two strings and the active objects are again at the tops of their control loops. Draw a sequence diagram that represents an interaction that would produce this output: PRODUCE: Producer #1 (buf.size = 3) WAIT-ON-FULL: Producer # CONSUME: Consumer #1 (buf.size = 2) PRODUCE: Producer #1 (buf.size = 3) WAIT-ON-FULL: Producer # CONSUME: Consumer #2 (buf.size = 2) Submit paper drawings to Scott in class or at his office hours on the day of the deadline. E-mail digital submissions to both Scott ([email protected]) and Greg ([email protected]).