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

Obelia, what do obelia eat and how do they feed

what do obelia eat and how do they feed

How memory utilization factor shall be computed, How Memory utilization fac...

How Memory utilization factor shall be computed  Memory utilization factor shall be defined as Memory in use/total memory connected

Linux, write a linux command to display lines from 25 - 45 of directory "/e...

write a linux command to display lines from 25 - 45 of directory "/edc/password"

Define an imperative statement, Determine an imperative statement Imper...

Determine an imperative statement Imperative statement points out an action to be carried out during execution of assembled program

Requirements memory management intended to satisfy?, Normal 0 f...

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

Deadlock, what are the overall concepts of deadlock

what are the overall concepts of deadlock

What are the various page replacement algorithms, What are the various page...

What are the various page replacement algorithms used for page replacement? FIFO page replacement Optimal page replacement LRU page replacement LRU approximat

Explain and differentiate programmed and interrupt i/o, Question 1 Explain...

Question 1 Explain the structure of operating system in detail Question 2 Explain the following scheduling algorithm                                     1) First come Firs

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