CSE 430 - Operating Systems
Spring 2009
Project #2 and Project#3
 

Project #2: Semaphores.
Due: This project is not to be turned it... it is a stepping stone to Project 3.


Implement semaphores, as discussed in class, using the threads you have implemented. Since the threads are non-preemptive, you do not need to ensure atomicity of the semaphores (they are already atomic).

Implement the following:

  1. Semaphore data structure: A value field and a queue of PCBs.

  2. InitSem(semaphore, value): Initializes the value field with the specified value.

  3. P(semaphore): The P routine decrements the semaphore, and if the value is less than zero then blocks the process in the queue associated with the semaphore.

  4. V(semaphore): The V routine increments the semaphore, and if the value is 0 or negative, then takes a PCB out of the semaphore queue and puts it into the run queue.
    Note: The V routine also "yields" to the next runnable process.

  5. Implement a set of processes to test the semaphores. The easiest is to have 3 or 4 processes in infinite loops, each of which prints a line, sleeps for 1 sec and then signals the next process to proceed. The signaling is done by semaphores and not by yielding.

 

Project #3
Due: May 4th (last class).


Using the semaphores you have implemented, implement the Readers and Writers Problem. Design how you want to get the processes to print, such that you can see which process if doing what (reading, writing, waiting, or in the "remainder section" etc).

This project will be executed for grading. Submission method to be determined.