Question: Write a C/C++ multi-threaded application to simulate the above scenario. You can consider the worker to the right as the producer and the worker to
Write a C/C++ multi-threaded application to simulate the above scenario. You can consider the worker to the right as the producer and the worker to the left as the consumer. Program must adhere to the following.
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:
Goal: To Learn Thread Simulation 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. Large Bags Count Medium Bags Count Small Bags Count Shared Location Bags (Large, Medium, Small) Boxed and Miscellaneous Items Moving on a Convoy Belt Boxes a Miscellaneous Items Count This worker will take bags from shared location stack them on appropriate shelves and keep a count on each type. this worker will take bags from the convoy belt and places them on the shared location Write a C/C++ multi-threaded application to simulate the above scenario. You can consider the worker to the right as the producer and the worker to the left as the consumer. Program must adhere to the following. 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: LMLMMMLSMSMMSMLLMSMLLMMMMSLLMMBLMmLSSLMMMMS SBMBBLSLLSMSMLBmMmD 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: Goal: To Learn Thread Simulation 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. Large Bags Count Medium Bags Count Small Bags Count Shared Location Bags (Large, Medium, Small) Boxed and Miscellaneous Items Moving on a Convoy Belt Boxes a Miscellaneous Items Count This worker will take bags from shared location stack them on appropriate shelves and keep a count on each type. this worker will take bags from the convoy belt and places them on the shared location Write a C/C++ multi-threaded application to simulate the above scenario. You can consider the worker to the right as the producer and the worker to the left as the consumer. Program must adhere to the following. 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: LMLMMMLSMSMMSMLLMSMLLMMMMSLLMMBLMmLSSLMMMMS SBMBBLSLLSMSMLBmMmD 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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
