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 wait for graph, Explain Wait for Graph a. Use a resource alloca...

Explain Wait for Graph a. Use a resource allocation graph to derive a wait-for graph.  b. Wait-for graph acquired by making an edge from p 1 to p 2 iff p 1 is waiting for

Why is rotational latency is not taken in disk scheduling, Why is rotationa...

Why is rotational latency usually not considered in disk scheduling? How would you modify SSTF, SCAN, and C-SCAN to include latency optimization? Most disks do not export their

DOS, Ask question #Minimum 500 words accepted#

Ask question #Minimum 500 words accepted#

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?

Can page tables be set up to replicate base registers, Q. We have an OS (o...

Q. We have an OS (operating system) for a machine that uses base and limit registers however we have modified the machine to provide a page table. Can the page tables be set up to

How many disks can be used effectively by one fast wide bus, Q. More than ...

Q. More than one disk drive is able to be attached to a SCSI bus. Especially a fast wide SCSI-II bus can be connected to at most 15 disk drives. Remember that this bus has a bandw

Determine the value to be loaded in relocation register, Refer a program wi...

Refer a program with a linked origin of 5000. Suppose the memory area allocated to it have the start address of 70000. Determine the value to be loaded in relocation register?

What is a real-time system?, What is a Real-time system? A Real-time sy...

What is a Real-time system? A Real-time system is used when inflexible time requirements have placed on the operation of processor or the flow of data so it is often used as a

Explain benefits of time-sharing system, Under what circumstances would a ...

Under what circumstances would a user be better off using a time-sharing system, rather than a personal computer or single-user workstation? When there are some other users, th

Necessary conditions for deadlock, Here are the conditions necessary for a ...

Here are the conditions necessary for a deadlock to occur; note that all of them are necessary, and none is suf?cient: 1. ?nite resources: the resources are held in a mutually-e

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