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

What is the use of FIFOs in client-server applications, What is the use of ...

What is the use of FIFOs in client-server applications

Define the non monolithic coding, Define the Non Monolithic Coding Fir...

Define the Non Monolithic Coding First off, client - server developers must adopt a new programming mindset. Much as with the shift to object - oriented design, developers sho

Explain the circumstances under which os use mutexes, Q. Give the reasons ...

Q. Give the reasons why Windows XP, Solaris and Linux implement multiple locking mechanisms. Explain the circumstances under which they use mutexes, spinlocks, semaphores, adaptiv

Principles of operating systems, Objective - Tiny Shell (tish) In this...

Objective - Tiny Shell (tish) In this exercise you will write a small shell program to run different programs in foreground and background mode. Background Usually when

Why page sizes always powers of 2, Q. Why page sizes always powers of 2? ...

Q. Why page sizes always powers of 2? Answer: Recall that paging is executed by breaking up an address into a page and offset number. It is most competent to break the address

Quick, why we say " OS is a resource allocator" and “OS is a control progr...

why we say " OS is a resource allocator" and “OS is a control program"?

What is the use of system calls, Q. What is the use of system calls? A...

Q. What is the use of system calls? Answer: System calls permit user-level processes to request services of the operating system.

Cpu, what is cpu

what is cpu

Define properties of real time operating system, Define properties of Real ...

Define properties of Real time operating system Real time :- Often used in a dedicated application, this system reads information from sensors and must respond within a fixed a

Determine the syntax of the fork and join primitive, Determine the syntax o...

Determine the syntax of the Fork and Join Primitive  Answer: Syntax of the Fork and Join Primitive is as follow: Fork Join

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