Computer Science 330
Operating Systems

Fall 2020, Siena College

Lab 6: Synchronization Problems Practice
Due: 11:00 AM, Monday, October 12, 2020

In this lab (more like a mini problem set), you will practice coming up with semaphore-based solutions to synchronization problems.

You may work alone or with a partner or two on this lab. However, in order to make sure you learn the material and are well-prepared for the exams, those who work in a group should either collaborate closely while completing the problems or work through the problems individually then discuss them within your group to agree on a solution. In particular, the "you do these and I'll do these" approach is sure to leave you unprepared for upcoming tasks and the exams.

Learning goals:

  1. to gain experience using semaphores to solve synchronization problems

Getting Set Up

You will receive an email with the link to follow to set up your GitHub repository, which will be named synchronization-lab-yourgitname, for this lab. Only one member of the group should follow the link to set up the repository on GitHub, then others should request a link to be granted write access.

All GitHub repositories must be created with all group members having write access and all group member names specified in the README.md file by 4:00 PM, Friday, October 2, 2020. This applies to those who choose to work alone as well!

Synchronization Problems

For these questions, develop pseudocode for the actions of the cooperating processes. Use semaphores for synchronization. The only permitted operations are initialization, wait, and signal. You may assume the semaphores are fair. You may introduce other shared variables, but be careful about concurrent access.

Question 1: Consider this variation on the producer-consumer problem we studied in class. Assume one producer process and n consumer processes share a buffer, large enough to hold one item at a time. The producer deposits items into the buffer, consumers fetch them. Every item deposited by the producer has to be fetched by all n consumers before the producer can deposit its next item.

Question 2: In a far off land lives a wealthy but quite lazy man who enjoys sleeping and enjoys fancy chocolates. He would like to eat as many chocolates as he can, but does not want his sleep distrubed unless there is enough chocolate to satisfy him. To this end, he has hired n chocolatiers and purchased a candy dish that holds x fancy chocolates. The chocolatiers work continuously to produce single fancy chocolates. As soon as the candy dish fills, the chocolatier who placed the xth fancy chocolate wakes the man, who immediately eats all of the chocolates in one gulp. Your solution should synchronize the actions of the man and his chocolatiers.

Submission

You may submit a PDF of your solutions (handwritten or typeset OK) or write your answers (nicely formatted) in the README.md of your repository. In either case, submission requires that you commit and push.

Grading

This assignment will be graded out of 50 points.

Feature

Value Score
Question 1 25
Question 2 25
Total 50