Computer Science 322
Operating Systems

Mount Holyoke College
Spring 2010


Lab 5: Bounded Buffer with Semaphores
Due: 2:40 PM, Monday, March 29, 2010


We have short lab assignment as we return from spring break, some of your attention is taken by the exam a few more substantial lecture assignments. Please work individually on this lab assignment.


Bounded Buffer with Semaphores

Write a C program that implements the bounded buffer problem for an arbitrary number of producers and consumers and items to be processed (each specified by command-line parameters). If i items are to be processed by p producers and c consumers, each producer should produce (i)/(p) items and each consumer should consume (i)/(c) items. You may either check that these divide evenly and report an error if not, or account for the uneven division by having some producers or consumers process one extra or one fewer item.

Use POSIX threads to create your producers and consumers and use POSIX semaphores for synchronization. Your solution should avoid the busy wait from the class examples (other than any busy waiting that might takesplace inside a semaphore wait or signal operation, which is not your fault).

Write your program in a file called prodcons.c. You may (and should!) use the source code from any of the class examples as your starting point. Be sure to indicate clearly which code you borrow and which code you add or modify.

See the examples and man pages for more information on POSIX threads and POSIX semaphores. Please don't hesitate to ask questions!


Submission and Evaluation

This lab is graded out of 10 points.

By 2:40 PM, Monday, March 29, 2010, submit documented source code and a Makefile to allow easy compilation. All necessary files should be submitted by email to jteresco AT mtholyoke.edu.

Grading Breakdown

Makefile 1 point
Arbitrary numbers of producers/consumers/items 3 points
Correct usage of POSIX semaphores 4 points
Documentation 2 points