Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this lab, you will simulate a simple multithreading application with a producer and consumer problem. Modify Producer and Consumer Problem from the lecture note
In this lab, you will simulate a simple multithreading application with a "producer and consumer" problem.
Modify "Producer and Consumer Problem" from the lecture note so that it can use all buffer space, not "buffersize as in the lecture note. This program should work as follows:
The user will run the program and will enter two numbers on the command line. Those numbers will be used for buffersize and counter limit
The main program will then create separate producer and consumer threads.
The Producer thread generates a random number through a random number generator function, and inserts it into the buffer and prints the number. Increment counter.
The Consumer thread goes to the buffer, and takes a number in the proper order, and prints it out. Increment counter.
After the counter reaches its limit both threads should be terminated and returned to the main.
Main program terminates.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started