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 five services provided by an operating system, List five services prov...

List five services provided by an operating system. Explain how each provides convenience to the users. Explain also in which cases it would be impossible for user-level programs t

What is micro-kernel?, Question 1 What is Micro-kernel? What are the benef...

Question 1 What is Micro-kernel? What are the benefits of Micro-kernel? Question 2 Explain seven state process models used for OS with necessary diagram. Differentiate betwee

Explain about deadlocks, Q. Explain about Deadlocks? Deadlocks for (...

Q. Explain about Deadlocks? Deadlocks for (int i = 0; i // first find a thread that can finish for (int j = 0; j if (!finish[j]) { boolean temp = true; for

Transferring files from windows to unix, Transferring files from Windows to...

Transferring files from Windows to Unix Be very careful transferring files from Windows to Unix. If you do transfer a file from Windows to Unix open the file, in Unix, using vi

What do you meant by the term ergonomics, Question 1: "Three entities m...

Question 1: "Three entities must be accountable and responsible for accident prevention." (a) List and explain these three entities. (b) Discuss the role of workers in ma

Define the scheduling in multitasking, Define the Scheduling in Multitaskin...

Define the Scheduling in Multitasking Earlier we learned the concepts and advantages of multitasking. In a system in which one or more tasks( threads or processes) attempt to s

What are scheduling queues?, What are scheduling queues? Since the proc...

What are scheduling queues? Since the processes enter the system they are put into job queue. This queue contains all processes in the system. The processes that are exist in m

Linux, shell script that accepts two directory names as arguments and delet...

shell script that accepts two directory names as arguments and delete those file in the second directory that are identical to the file in the first

Briefly discuss on real-time scheduling, Briefly discuss on real-time sched...

Briefly discuss on real-time scheduling? It is divided into two types.  Hard real-time systems are needed to complete a critical task within a guaranteed amount of time. T

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