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

Linux OS, Ask questioDevelop a utility in C language which will run in Linu...

Ask questioDevelop a utility in C language which will run in Linux operating systems to display following properties of the system: ? Processor speed ? Ram size ? Computer name ? S

Write a short note on file organization and access, Write a short note on f...

Write a short note on file organization and access. There are three methods to access files 1Record Access 2Sequential Access 3Random Access The record access

Define deadlock avoidance, Define deadlock avoidance. An alternative me...

Define deadlock avoidance. An alternative method for avoiding deadlocks is to need additional information about how resources are to be requested. Every request requires the sy

Pthreads, A thread is defined as an independent stream of instructions that...

A thread is defined as an independent stream of instructions that can be scheduled to run as such by the operating system. Each program contains a number of threads which can be ru

Describe the possible rmi invocation semantics, Question: (a) Explain t...

Question: (a) Explain the similarities and differences between two different threads running in the same process and two independent processes. When would you want to use two t

Explain fixed partitioning, Explain fixed partitioning. Partitioning ar...

Explain fixed partitioning. Partitioning are the simpler techniques that don't involve virtual memory. Partitioning has been used in numerous variations in operating systems.

What is low-level formatting, What is low-level formatting? Before a di...

What is low-level formatting? Before a disk can kept data, it must be required into sectors that the disk controller can read and write. This procedure is called low-level form

Explain the threadswitchwithdelay function used in netware, Explain the Thr...

Explain the ThreadSwitchWithDelay Function used in Netware ThreadSwitchWithDelay( )   This command is used when threads are waiting for an event or resource but don't want 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