in this exercise we are going to use


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.

Request for Solution File

Ask an Expert for Answer!!
Operating System: in this exercise we are going to use
Reference No:- TGS0416923

Expected delivery within 24 Hours