Question
Write a program that creates an array of length 10, then creates 8 threads. a. The first four should start creation of random numbers of
Write a program that creates an array of length 10, then creates 8 threads.
a. The first four should start creation of random numbers of values between 0 and 1000, then enters their critical sections that are controlled through semaphores, and write the generated value into the pre-defined array and into a file named "Producers activity" with the following format: "Producer number- produced item number -with the value -" The total of four producers should produce a total of 10,000,000 random values
b. The second four should request entrance to their critical sections that is controlled through semaphores, read the values written in the array, and write it to the screen with the following format: "Consumer number - consumed item number-with the value -" And to a file named "Consumer activity", then exit the critical section, and repeat till the producers stop production. The total number of elements generated by the producer and consumed by the consumers should be 10,000,000 number
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