Question: Write a C/C++ multi-threaded application to simulate the below scenario. Think about a primitive Bag Handling Belt Conveyor system. Bags move in a Conveyor belt
Write a C/C++ multi-threaded application to simulate the below scenario.
Think about a primitive Bag Handling Belt Conveyor system.
Bags move in a Conveyor belt in three different sizes (Large, Medium and Small). There are miscellaneous items also. All miscellaneous items can be considered as one type.
The worker on the right picks up bags and miscellaneous items one by one and place it in the shared location. The second worker to the left picks up bags, boxes and miscellaneous items one by one and arrange them in to shelves while keeping a count of each item type.
a. Main program create and invokes two threads namely the producer and the consumer.
b. Producer opens and reads a text file (representing the commodities on the belt) character by character
and put each character into a global character memory location. When each time the producer reads a
character and then puts to the global location, we consider an item is produced. The file contains a text
string like this:
LMLmMMLSMSMMSmLLMSMLLmMMMSLLMMBLMmLSSLMmMMSSBmBBLSLLSMSMLBmMmD
L = Large Bag M = Medium Bag S = Small bag
m = Miscellaneous Item B = Box D = Done (end of items).
The last character written to the shared location is the character D (Done) indicating the end of items on
the belt. Then the Producer closes the file. Producer completes.
c. Consumer on the other end reads the character in the shared location (we consider the value in the
shared location is consumed), and increments globally defined counts depending on the bag type, a box
or miscellaneous items received. Then we assume the picked up item is put into a proper shelf. When the
last character D is consumed, the Consumer completes.
d. The main program who created and invoked the two threads (Producer and Consumer) will wait until the
two threads complete their jobs and then prints the Bag Counts as follows
e. You must simulate this scenario in a way that the program will
run at least for a minute and at most for 2 minutes. Use the
sleep() and/or usleep() system calls to control the execution
speed of the application.
f. Read the file character by character. NO BUFFERED READING.
g. Use proper Mutexes in both the threads.
h. Create two threads. Make sure to join the two threads.
I. Use proper system calls. You are free to use system calls you
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
