Homework 4

Create solutions to the following problems in Chapter 5 of the Concurrency textbook: 5.1 and 5.6.

Where the book says "Java", you can substitute any other programming language that supports similar concurrency features.

In the case of 5.1 write a test program that shows that no matter how many threads access the buffer, its semantics is maintained. That is, if I put object A into the buffer, then before object B can be placed in the buffer then some other thread has retrieved object A. What goes in, must come out! At a minimum, have three threads puting things into the buffer and three threads pulling things out of the buffer.

In the case of 5.6, write a test program that shows that no matter how many threads access the bank account, its balance is never less than zero or greater than MAX. (You get to pick the value of MAX.) Have at least three threads sharing the account with each one attempting to withdraw money from and deposit funds to the account.

Place the source code for 5.1 in one directory and the source code and FSP specification for 5.6 in a second directory. Place those directories in a third directory called <HW4_LASTNAME>, archive that directory into a file called <HW4_LASTNAME.zip> and send it to me as an attachment in an e-mail message.

You may NOT work in teams on this assignment. Please write the honor code statement as a comment at the top of at least one of your source code files. The honor code statement is:

On my honor as a University of Colorado at Boulder student, I have neither given nor received unauthorized assistance on this work.

This homework is due by 11:59 PM on Friday, March 20th.

This homework is worth 40 points (20 points for each question).

Kenneth M. Anderson, 2009