Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C language Program for the Given Question Using Bounded Buffer Logic. In this assignment, you will create a process that uses threads to

Write a C language Program for the Given Question Using Bounded Buffer Logic.
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.
Conditions:
1) In Each Producer and Consumer, the following Sections need to be clearly identified: entry, critical, exit, and remainder sections.
2) Explain the code using Comments Clearly.
3) There should be no race cases. All race cases should be ignored. (Marks will be deducted if found any race cases)
4) Explain implementation of Threads, Semaphores, mutex using comments.
5) Explain working of logic using Comments.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Server T-SQL Recipes

Authors: David Dye, Jason Brimhall

4th Edition

1484200616, 9781484200612

More Books

Students also viewed these Databases questions

Question

Describe Table Structures in RDMSs.

Answered: 1 week ago