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

List antivirus techniques used for protection purposes, Question: a) Th...

Question: a) There are main goals of data security. List them and elaborate on how they provide protection. b) Describe threats associated with data security. c) Describe

Determine what the expansion of nested macro calls follows, Determine what ...

Determine what the expansion of nested macro calls follows  The expansion of nested macro calls follows the Last in First out (LIFO) rule.

Define the sleep (sec) function, Define the Sleep (sec) Function Sleep ...

Define the Sleep (sec) Function Sleep function suspends execution of this process for sec number of seconds. While this function is used in our example for consistency, other f

What is time-stamping, time-stamping It is a method proposed by Lampor...

time-stamping It is a method proposed by Lamport, used to sequencing events in a distributed machine without the use of clocks. This process is intended to order events consis

Explain the os/2 operating system, Explain the OS/2 Operating System Li...

Explain the OS/2 Operating System Like NetWare, OS/2 manage resources at three levels, as shown in Figure 4.5 Resources may be maintained at the session, process, and thread le

Memory hierarchy, Difference between cache and associate memory

Difference between cache and associate memory

What is the occupation of the object manager, Q. What is the occupation of ...

Q. What is the occupation of the object manager? Answer: Substance present a generic set of kernel mode interfaces to user mode programs. Objects are influenced by the execut

Define enforcing modularity for c, Define Enforcing Modularity for C Ad...

Define Enforcing Modularity for C Additionally, in C it is sometimes necessary to create modularity of design. C++  is very natural model for component based application design

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