Single Producer and multiple consumer using multithreating
This project has been awarded to it2051229 for $50 USD.Get free quotes for a project like this
Project Budget$30 - $250 USD
In this project, we simulate a tandoori chicken lunch buffet restaurant with one chef and
multiple guests, which is similar to a single producer/multiple consumers problem. We
implement one program with multiple threads, each of which holds either a chef or a guest.
We also apply one synchronization tool – semaphores, which can solve an issue for
synchronizing common resources with multiple threads. Through this project, we will learn
how to create multi-threaded process and how to synchronize threads using semaphores.
A. Producer - consumer problem
The restaurant resembles a producer consumer problem: in a producer side, chefs are cooking
and providing food, guests are trying to eat it when it is available. When simulating the
restaurant, we have some issues, each of which can be utilized by using concepts learnt in the
First, we need executable units, each of which can run simultaneously during execution. Also
some resources such as food and dining tables should be shared by all guests.
Multiprogramming can be a good approach, but it brings us other issues we need to consider –
parallel programming or even concurrent programming. Therefore, we will apply alternative
approach using multithreading, which costs less than the approaches. We will briefly review
this concept in the subsection B.
Second, we should manage the shared resources, e.g., food and dining tables, without any
conflicts. Two guests may race to get one food, and the racing game will cause some unhappy
and uncomfortable situation. These resources are so critical that we need to have a powerful
tool. We can address this issue and find a powerful solution – semaphore. Semaphores can
enable us to access the critical resources without any conflicts. We will briefly review this
concept in the next subsection C.
For simplifying this project, we model a small restaurant in which one chef works.
B. Multi-threaded process
Process defines an executable unit to perform a task, which is called a thread. If the process
needs to run one task at the one moment, one thread is enough to be created, because the
created thread may hold the next task. This process is called a single-threaded process, and
this design does not fit for processes which needs to run multiple tasks simultaneously. This
issue is solved by multi-threaded design, in which multiple threads can be created and run. For
more information, review the chapter 4.
CS 5500 Project 2
University of Central Missouri 2
When multiple threads are running simultaneously, they may access the same resources
declared as global variables. It has many potential problems because some changes by one
thread affect other threads which need the previous information. This conflict may cause
severe problems and must be avoided. Synchronization tools are developed to solve this
problem. Semaphores are one of the tools. There are two types of semaphores – binary
semaphore (similar to mutex) and counting semaphore. A thread which obtains the semaphore
can access the critical resources, whereas other threads should wait until the semaphore is
available to get. Using the semaphores, we can control accesses to the critical resources. For
more information, review the chapter 5.
The program has the similar format as the first project. When user starts the program, it will
show the prompt after group ID consisting of section # and group # (that is,
section#_group#> $). To simulate the restaurant, user will the following command with three
tcr -option -Number of cooked food –Number of dining table
You have any question mail me.
Browse Related Skills
Other things people do on Freelancer
Looking to make some money?
- Set your budget and the timeframe
- Outline your proposal
- Get paid for your work
Hire Freelancers who also bid on this project
Looking for work?
Work on projects like this and make money from home!Sign Up Now
- The New York Times
- Wall Street Journal
- Times Online