Producer - consumer system, Operating System

Assignment Help:

In this exercise we are going to use  pthread()to simulate the dynamics between a warehouse, factory and retail. The factory produces product by using parts supplied by the warehouse and ship to the retail outlet for sale. The production and sale of product manufactured by the factory happen at a fixed periodic rate. If the factory manufacture faster than it takes the retail to sell the products then the factory production must be suspended. The  factory must monitor the total stock at the retail outlet and suspend production if the retail is overstocking. The retail will need to monitor its own stock level and suspend its operation if its inventory is empty. The warehouse will monitor if the parts level at the factory is depleted and replenish the parts. Each time a unit of goods is sold the total revenue will be incremented by three while production and parts will decrement the revenue by one. The whole operation will be terminated if the total revenue reached a predefined 

Modify the  intro.c program such that we are using the pthread() function to create three threads. One thread is called factory, another is called retail and the third is called warehouse.

First thread: the factory thread should increment a global counter variable called  product and decrement the global counter parts and revenue every factory_delay seconds. It should suspend its increment of the product when the counter is greater than or equal to max_product. Production can resume if the product counter is less than max_product.

Second thread: the retail thread should decrement the product counter by one and increment the revenue counter by three every retail_delay seconds. It should suspend its operation if the product counter is 0.

Third thread: the warehouse thread should act as the warehouse that supplies all the parts to the factory for product manufacturing. It will check for the parts counter value every warehouse_delay seconds. If the parts counter is equal to zero it will increment the counter by two and decrement the revenue counter by one.

The entire program will be terminated if the revenue counter reaches a total value of max_revenue. Each time the  factory thread updates any variable it should display whether it is producing or suspending, total amount of parts, total products and the total revenue in the account. Each time the retail thread updates any variable it should display the  total amount of products in stock and the total  revenue. For the  warehouse thread it should display the current value of  parts and revenue.  Since the global variable  product,  revenue  and parts are referenced by more than one thread, therefore you will need to setup a mutex variable for each of these variables.


Related Discussions:- Producer - consumer system

Difference between internal and external fragmentation, Explain the differe...

Explain the difference between internal and external fragmentation. Internal Fragmentation is the area in a region or a page that is not used by the job occupying that region o

Define dynamic linking, Define dynamic linking. Dynamic linking is same...

Define dynamic linking. Dynamic linking is same to dynamic loading, rather that loading being postponed unless execution time, linking is postponed. This feature is usually use

Process states in linux, Process states in Linux OS Running:  Process ...

Process states in Linux OS Running:  Process is either ready to run or running Interruptible:  a Blocked part of a process and waiting for a signal or an event from anothe

Define the client - server communications environment, Define the Client - ...

Define the Client - Server Communications Environment Today's client - server communications environment offers programmers great flexibility for application design. Applicatio

Write knowledge base relevant propositional statement, Suppose a logic-base...

Suppose a logic-based agent in the wumpus world has found that locations (1,1) and (2,1) do not contain a stench, but that locations (3,1) and (2,2) do contain a stench. Can the ag

What is an operating system process, What is an operating system process? H...

What is an operating system process? How is it different from a program? Why do we need the concept of a process, rather than simply talk about programs running in memory? The e

Define the division of labour between client and server, Define the Divisio...

Define the Division of Labour between Client and Server Given our definition of client - server as the interaction between dispersed application logic components it must be not

Write a script in linux to match a data directory, Write a script that uses...

Write a script that uses this idea to print output similar to the following: Files in this directory that match *~ : bash-scripts.html~ chimpanzee~ countdown~ countd

What is a dispatcher, What is a Dispatcher? The dispatcher is the modul...

What is a Dispatcher? The dispatcher is the module that gives control of the CPU to the process selected by the short- term scheduler. This function includes: Switching

What are the system components of an operating system, What are the system ...

What are the system components of an operating system and explain them? a) Process management b) Main-memory management c) I/O management d) File management e) Seco

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd