Explain producer-consumer problem using semaphores, Operating System

Assignment Help:

Producer-Consumer Problem Using Semaphores

The Solution to producer-consumer problem use three semaphores namely- full, empty and mutex.

The semaphore 'full' is utilized for counting the number of slots in the buffer that are full. The 'empty' for calculate the number of slots that are empty and semaphore 'mutex' to make sure that the producer and consumer don't access modifiable shared section of the buffer simultaneously.

Initialization

  • Set full buffer slots to 0.
        i.e., semaphore Full = 0.
  • Set empty buffer slots to N.
        i.e., semaphore empty = N.
  • For control access to critical section set mutex to 1.
        i.e., semaphore mutex = 1.

Producer ( )
WHILE (true)        
            produce-Item ( );
        P (empty);
        P (mutex);
        enter-Item ( )
        V (mutex)
        V (full);

Consumer ( )
WHILE (true)
        P (full)
        P (mutex);
        remove-Item ( );
        V (mutex);
        V (empty);
        consume-Item (Item)


Related Discussions:- Explain producer-consumer problem using semaphores

Explain the various types of computer systems, Explain the various types of...

Explain the various types of computer systems. Mainframe systems Large Number of CPU with Greatest Processing Power:  Huge Memory Capacity:  Increased Performance by s

Relationship among the capabilities of domain level j and i, Q. In a ring-...

Q. In a ring-protection system the level 0 has the greatest access to objects and level n (greater than zero) has fewer access rights. The access rights of a program at a partic

Define computer system environment, Q. List three instances of deadlocks th...

Q. List three instances of deadlocks that aren't related to a computer system environment. Answer: Two cars passage a single-lane bridge from opposite directions.

What is page fault, Problem: a) The CPU can access 2 storage devices di...

Problem: a) The CPU can access 2 storage devices directly. What are these 2 storage devices? b) Define 2 key issues involved in memory management. c) How do processes sha

What is the concept of an atomic operation, Question: Concurrency and Sync...

Question: Concurrency and Synchronization a) Define the following terms: I. Critical section II. Mutual Exclusion III. Deadlock IV. Starvation. b) Name three methods w

Can we call trap as an interrupt??, is there any difference between the tra...

is there any difference between the trap and interrupt??

What are the issues in designing a network, Normal 0 false fa...

Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4

Cache replacement policies, The physical memory acts as a cache backed by t...

The physical memory acts as a cache backed by the disk. When the physical memory is full, and we want to read in another page from disk, we have to evict a page from physical memor

Explain acyclic-graph directories, Acyclic-graph directories An acyclic...

Acyclic-graph directories An acyclic graph permits directories to have shared subdirectories and files. The similar file or subdirectory may be in two dissimilar directories. A

Semaphore examples, Ok so i think i got this right by not 100% on this. wha...

Ok so i think i got this right by not 100% on this. what I want to figure out is if there are x visitors that can line up for a ride but only 1 passenger can get on the ride at a 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