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

Copy on write in virtual memory, how copy on write on pages when many proc...

how copy on write on pages when many process works at a same time?

Multiprogramming., In a multiprogramming and time sharing environment sever...

In a multiprogramming and time sharing environment several users share the system simultaneously .what are two such problems?

Designing issues in a network-scalability, Scalability Scalability is t...

Scalability Scalability is the ability of the system to adapt to increased service load. A scalable system will respond more gracefully to increased load than a non scalable on

Defining kernel, Problem 1. What is kernel? What are the main component...

Problem 1. What is kernel? What are the main components of a kernel? Defining Kernel Explaining Main components of Kernel 2. What is mutual exclusion? What are i

Inventory differences, What makes a Just-in-Time inventory system differ fr...

What makes a Just-in-Time inventory system differ from a traditional inventory system?

Define the properties of interactive operating system, Define the propertie...

Define the properties of Interactive operating system Interactive:- This system is composed of many short transactions where the results of the next transaction may be unpred

Explain signal handling, Signal handling A signal is used in UNIX syste...

Signal handling A signal is used in UNIX systems to inform a process that a particular event has occurred. 1. A signal is produced by the occurrence of a particular event.

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