Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The general problemtargets using Pthreadprocesses to work collaborativelyand concurrentlyonashared resource. The program targets to developand implementa Bonded-Bufferwhere severalProducersmake itemstoadd into the buffer, whileseveral Consumerstry to

The general problemtargets using Pthreadprocesses to work collaborativelyand concurrentlyonashared resource. The program targets to developand implementa Bonded-Bufferwhere severalProducersmake itemstoadd into the buffer, whileseveral Consumerstry to receive theseitemsfrom the buffer toconsume.

Producers & Consumers is a classic operating system problem demonstrating shared resources with multiple complication. Lab 3 covers Part 1 of the problem having only a singleproducer thread and a single consumer process thread. These two threads share one single buffer with a limited size of 10, and both exit when they have walked through the buffer.

Write a C++ programcalled thread.cppand make an executablewiththreadand a log filecalledthread.logfor this part of your assignment.

There isa 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-timeto consume, but each time beforeaccessing the buffer,it waits certainamount oftime for the item to be produced.The buffer in this part, has a limited sizeof 10.When 10 itemsareproducedor consumed, the program terminates.

Consumerin this part (and for simplicity)can use abusy-loopfor 10000 iterations. Inside the loop, there isa simple tasklike multiplying two numbers saving in third one; e.g. c=a*b. This busy loop forces the consumer towait a bit![It Part 2 of the problem, we will replace itwith real waiting condition.]

Create two Pthreads,one as producerand the second one as consumer. The producer generates a random number between 1 and1000(simulating an item) and inserts it in the buffer. Theconsumer threadfetches these randomnumbers(one at a time)and considers them as products to consume.

At the endof the program,the parentthread(the main program)reportstheMin, Max, Avg of the items.

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

Contemporary Issues In Database Design And Information Systems Development

Authors: Keng Siau

1st Edition

1599042894, 978-1599042893

More Books

Students also viewed these Databases questions