Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 1: Producer-Consumer Problem Here, we have a set of p producers and c consumers, each running as a single thread. They are synchronized via

image text in transcribedimage text in transcribedimage text in transcribed

Problem 1: Producer-Consumer Problem Here, we have a set of p producers and c consumers, each running as a single thread. They are synchronized via shared buffer of size b (i.e., it can accommodate b items) Each buffer item contains the following information: Sales Date (DD/MM/YY), store ID (integer), register# (integer), sale amount (float). Each item represents a sales record from a specific cashier register in a particular location of a retail-chain. Thus, each producer reports sales from a specific store location. Each consumer represents an entity that reads sales records and computes sales statistics locally. Each buffer item is consumed by one and-only-one consumer. When all sales records have been read (indicated by a special flag set by another designated thread), each consumer adds its local statistics to the global statistics (in the shred space). It also prints its own local statistics along with its ID. In addition, your main program (parent process) prints the overall (global) statistics. The statistics to be maintained are: Store-wide total sales Month-wise total sales (in all stores) Aggregate sales (all sales together Total time for simulation (from begin to end) Each producer produces records randomly. Assume that the DD field is 1-30, MM is 01- 12, and YY is always 16. Store IDs are in the 1 to p range (where p is the number of producers). The register numbers range from 1-6 for any store. The sale amount in each item can range between 0.50 and 999.99. Each producer generates its record with random data. Run the program until 10,000 items are produced by all producers together Obviously, the number of items produced so far (by all producers) need to be maintained in shared memory. Each producer is assigned a fixed store ID when it is created. It has the following structure

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_2

Step: 3

blur-text-image_3

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

Essential SQLAlchemy Mapping Python To Databases

Authors: Myers, Jason Myers

2nd Edition

1491916567, 9781491916568

More Books

Students also viewed these Databases questions