Operating Systems, CSCE 4413

Homework Assignment 4

As before, this assignment is to be done on your own, and with the help of the textbook or other legitimate resources.

Part 1: Written Exercises

Write the answers to these in plain text and submit the file to the Homework Submission Page.

  1. From the text, do exercises 8.2, 8.4, 8.5, 8.8, and 8.13.
  2. From the text, do exercises 9.5, 9.10, and 9.17a.
  3. From the text, using the table in exercise 9.16, what are the physical addresses for the following logical address? (Note that 0,430 means a reference to segment 0, byte 430.)
    1. 0,430
    2. 1,10
    3. 2,500
    4. 3,400
    5. 4,112

Part 2: Programming Exercise

The goal of this assignment is to write a program that uses a monitor to synchronize access to a set of shared resources. I would like for you to write a multithreaded program to simulate the problem described in exercise 7.9 in the text. You may write your program in C or C++ using pthread condition variables, or you may use Java.

To prepare: Study the class materials and on-line man pages for how to use condition variables in the pthreads library.

Specification: Write a multithreaded program that consists of a main thread, three smoker threads and one agent thread. The smoker threads and the agent thread should run in a loop indefinitely. The loop is similar to the producer/consumer psuedocode examples that we have used in class. Use the sleep command or user input to make the output understandable on the screen.

The agent thread should randomly select two of three ingredients, tobacco, paper, and matches and place them on a table. Your program should output which item has been selected. One of the smoker threads has paper, another has tobacco, and another has matches. The smoker who has the remaining ingredient should be signalled. The signalled thread should output a message when it executes. The agent should wait while the smoker thread executes, and the smoker thread should then signal the agent when it is complete.

This cycle will continue indefinitely. You can terminate your program with a control-C at the command line. As before, use use good programming practice (e.g., put in a sufficient number of comments to explain what your program does, use good formatting, and so on).

Submit your source file and Makefile to the Homework Submission Page.

Enjoy!