Question: Write a C++ program called thread.cpp and make an executable with thread and a log file called thread.log for this part of your assignment. 1

Write a C++ program called thread.cpp and make an executable with thread and a log file called thread.log for this part of your assignment. 1 of 2 Detail Specification: There is a buffer with S=10 (the size of buffer is 10). The producer makes 10 items and add them to the buffer in order of 1, 2, 3 to 10 and stops. The consumer goes to the buffer 10 times and gets one-item-at-a- time to consume, but each time before accessing the buffer, it waits certain amount of time for the item to be produced. The buffer in this part, has a limited size of 10. When 10 items are produced or consumed, the program terminates. Consumer in this part (and for simplicity) can use a busy-loop for 10000 iterations. Inside the loop, there is a simple task like multiplying two numbers saving in third one; e.g. c=a*b. This busy loop forces the consumer to wait a bit! [It Part 2 of the problem, we will replace it with real waiting condition.] Create two Pthreads, one as producer and the second one as consumer. The producer generates a random number between 1 and1000 (simulating an item) and inserts it in the buffer. The consumer thread fetches these random numbers (one at a time) and considers them as products to consume. At the end of the program, the parent thread (the main program) reports the Min, Max, Avg of the items. Write a C++ program called thread.cpp and make an executable with thread and a log file called thread.log for this part of your assignment. 1 of 2 Detail Specification: There is a buffer with S=10 (the size of buffer is 10). The producer makes 10 items and add them to the buffer in order of 1, 2, 3 to 10 and stops. The consumer goes to the buffer 10 times and gets one-item-at-a- time to consume, but each time before accessing the buffer, it waits certain amount of time for the item to be produced. The buffer in this part, has a limited size of 10. When 10 items are produced or consumed, the program terminates. Consumer in this part (and for simplicity) can use a busy-loop for 10000 iterations. Inside the loop, there is a simple task like multiplying two numbers saving in third one; e.g. c=a*b. This busy loop forces the consumer to wait a bit! [It Part 2 of the problem, we will replace it with real waiting condition.] Create two Pthreads, one as producer and the second one as consumer. The producer generates a random number between 1 and1000 (simulating an item) and inserts it in the buffer. The consumer thread fetches these random numbers (one at a time) and considers them as products to consume. At the end of the program, the parent thread (the main program) reports the Min, Max, Avg of the items
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
