COSC 360

Operating Systems

Project 2

Due September 22nd (Friday)


This project gives you hands-on experience with the OS concept of concurrency.

To Do

Complete the following items:

  1. The program in file 'ex3.c' uses three processes (itself, plus two that it creates). Modify the code to achieve the same results using only two processes.
  2. Test the program in example 'ex4.c' repeatedly. Does it always print the same number of zeroes? Does it ever print a value of n other than 0 or 2000?
  3. Suppose three processes attempt to use function additem() in example 'ex6.c' at the same time. Explain the series of steps that occur, and give the value of the semaphore during each step.
  4. Modify the producer–consumer code in example 'ex5.c' to use a buffer of 15 slots, and have the producer and consumer synchronize in such a way that a producer can generate up to 15 values before blocking and a consumer can extract all values in the buffer before blocking. That is, arrange for the producer to write integers 1, 2, … in successive locations of the buffer, wrapping around to the beginning after filling the last slot, and have the consumer extract values and print them on the console. How many semaphores are needed?
  5. In example 'ex5.c', the semaphore produced is created with a count of 1. Rewrite the code so produced is created with a count of 0 and the producer signals the semaphore once before starting the iteration. Does the change affect the output?


For each coding problem, you can initially start with a copy of /home/xinu/xinu/system/main.c, but you can comment out almost everything in /home/xinu/xinu/system/main.c and replace it with your code. This will allow you to restore /home/xinu/xinu/system/main.c to how it originally was, and allows me to easily run your code on my machine. For each code file you submit, put it in a separate directory (name the directory the number of the problem, such as "2".), but keep the name of the file as 'main.c'.

Any non-coding questions (where you type out your response), should be typed up and saved together in a file called 'project2.pdf'.

To submit, compress/zip all your files together (you *should not* submit the entire directory of Xinu source code), name it "project2", and submit it to Moodle by the due date.