Overview

CSCI 356 - Operating Systems - Fall 2012

Programming Assignment #2

Objective

Learn to implement a semaphore using a monitor construct with a condition variable. This assignment may be implemented using C, Java, or Python.

Linux Tutorial: POSIX Threads (for C programming)

Note that compilation on Linux requires passing the -lpthread switch to gcc or clang.

If using Java, note that the monitor is implemented by declaring both the acquire and release methods to be synchronized, then calling the built-in wait() function inside a loop that checks the counter variable (in the acquire method). In the release method, be sure to call the built-in notifyAll() function after incrementing the counter.

In Python, use threading.Condition to implement the monitor.

Assignment

Implement a semaphore class (or, if using C, a set of functions that operate on a shared semaphore variable) using a monitor. Verify that your solution works by testing it with the Dining Philosophers problem, following the example code.

Note that this assignment is intentionally under-specified. I will be out of town on Monday, October 15th, and Wednesday, October 17th. I want you to practice approaching a difficult programming assignment and see what forward progress you can make before I return. We will continue working on this assignment during the week of October 22nd.

You MAY work together, as usual.