Dana Vrajitoru
B424/B524 Parallel and Distributed Programming

B424/B524 Homework 3

Due date: Thursday, September 17, 2020.

Ex. 1 The hungry birds problem

In a nest there are n baby birds and one parent bird. The baby birds eat out of a common dish that initially contains F portions of food. Each baby repeatedly eats one portion of food at a time, sleeps for a while, and then comes back to eat. When the dish becomes empty, the baby bird who empties the dish awakens the parent bird. The parent refills the dish with F portions, then waits for the dish to become empty again. This pattern repeats forever in theory. Practically, the parent will refill the bowl only for a pre-determined number of times.

Write a program using the pthread library to simulate this problem. Input the numbers n and F from the user. Allow the parent to refill the dish for a limited number of times and ask the user to input this number too. Make the babies and the parent output something related to their actions (eating ... refill ...) such that you can see if the system behaves as you expect it or not.

Note. To write this program, you can use the producer-consumer program as a starting point (save these in a separate folder from homework 1 and 2):
producer_consumer.cc
producer_consumer.h
main.cc
Makefile

If you work directly on a Linux system, you can copy them with the command
cp /home/dvrajito/public_html/teach/b424/hw3 ./
This will copy the folder containing the two files directly in your current folder.

The program can be compiled with the command make and run with prodc or ./prodc. Compilation instructions without the Makefile are also included in the comment to the producer_consumer.cc file.

Upload to Canvas:

Upload the files that you create and/or modify both .cc and .h. Upload the Makefile too if you modify it.