.. _lab_sync: Lab 2 - Multithreaded Programming and Synchronization ======================================================= * Based on the documentation and sample code in :ref:`programming` and :ref:`bounded_buffer`, develop a simulation program of the bounded buffer problem with 10 containers, 6 producers and 6 consumers. - Each producer or consumer should run in it's own thread. - Each time a product is produced or consumed, use a random number generator and the :meth:`sleep` method from the :mod:`time` module to cause the thread to sleep for a random amount of time between 1 and 10 seconds. .. hint:: Here is a small piece of code that loop for 5 times and each time sleeps for a random about of time. :: import random import time for i in range(5): x = random.randrange(1, 10) print("x = {}".format(x)) time.sleep(x) - Cause each producer and consumer to print when it acquires a container or deposits a container. - Maintain a shared buffer that tracks and prints how many containers have been produced and consumed. The producers and consumers should each stop after 30 items have been either produced or consumed. * Submit a short lab report as a plain text file explaining what you did in the activity and what you learned from doing it. Include your source code in your assignment submission.