Answered step by step
Verified Expert Solution
Link Copied!

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

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

Databases Theory And Applications 27th Australasian Database Conference Adc 20 Sydney Nsw September 28 29 20 Proceedings Lncs 9877

Authors: Muhammad Aamir Cheema ,Wenjie Zhang ,Lijun Chang

1st Edition

3319469215, 978-3319469218

More Books

Students also viewed these Databases questions

Question

2. What is the impact of information systems on organizations?

Answered: 1 week ago

Question

Evaluate the impact of technology on HR employee services.

Answered: 1 week ago