Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this assignment, you will create a process that uses threads to implement a multiprogramming scenario and provide synchronization between these threads to ensure data
In this assignment, you will create a process that uses threads to implement a
multiprogramming scenario and provide synchronization between these threads to
ensure data consistency. You will create four threads 2 producers and 2 consumers,
who will have access to a shared circular buffer of size 20. Each item in the buffer
should hold 1 integer. You can use an integer array as your shared buffer. Each of
the producer threads must update a slot in the buffer with values from 1 to 30 (using
a for loop with 30 iterations). Each of the consumer threads must update a shared
variable called SUM by reading the buffer one item at a time. Each consumer can
read any item in the buffer, but only 1 at a time. Each item should be read by exactly
1 consumer. Naturally, each consumer should read the shared buffer only when at
least one slot is full and each producer should write to the shared buffer when at least
one slot is empty.
In summary, you program must have a shared buffer and the shared variable called
SUM. You can create other shared variables as needed. You can use either
semaphores or mutexes to ensure that the threads are synchronized with each other.
After all the producers and consumers have completed the execution, you should
print the value of the shared variable SUM. The value of SUM, if your program is
void of race conditions, should be 930.
write the code in C language only.
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