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

Define system call, Define System Call A system call is a request that ...

Define System Call A system call is a request that is made by any program to the operating system for carrying out tasks - picked from a predefined set - which the said program

Explain concept of synchronization, Synchronization In communication am...

Synchronization In communication among processes messages passed may be blocking or nonblocking - also called as synchronous and asynchronous. Blocking send : The sending pr

Default domain controllers policy gpo, Question: (a) Distinguish betwee...

Question: (a) Distinguish between local and active directory Group Policy in Windows Server 2008? (b) Describe the three areas of account Policies that can be managed thro

Define the os/2 threads code, Define the OS/2 threads code The sample p...

Define the OS/2 threads code The sample program in Listing is very similar to the NetWare example. OS/2 commands are substituted for the pseudocode commands controlling thread

Operating systems structures, with the aid of diagrams describe the followi...

with the aid of diagrams describe the following OS structure monolithic,layered and client server.

Garbage collection, The dynamic memory allocator is a layer between the app...

The dynamic memory allocator is a layer between the application and the OS, managing heap objects. When a program requests memory from the allocator (via malloc(), for instance), t

What is starvation?, What is starvation? A main problem related to dead...

What is starvation? A main problem related to deadlock is starvation. Starvation is the circumstances where process waits indefinitely within the semaphore. Indefinite blocking

Define cpu scheduling, Define CPU scheduling. CPU scheduling is the met...

Define CPU scheduling. CPU scheduling is the method of switching the CPU among several processes. CPU scheduling is the basis of multiprogrammed operating systems. By switching

Explain relative file organization, Relative file organization A rela...

Relative file organization A relative file is an array of fixed-length slots and the records can be inserted in the first free slot found from the beginning of the file and

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