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 the protection problems, Q. In some systems a subdirectory is able...

Q. In some systems a subdirectory is able to be read and written by an authorized user just as ordinary files can be. a. Explain the protection problems that could arise. b.

Explain first fit allocation algorithm, Describe the following allocation a...

Describe the following allocation algorithms: a. First fit b. Best fit c. Worst fit   a. First-fit: search the list of available memory and all

Paging, Paging full question

Paging full question

Describe the purpose of the open and close operations, Q. Describe the pur...

Q. Describe the purpose of the open() and close() operations. Answer: The open() operation notifies the system that the named file is about to become active. The c

What is an effector process, What is an effector process? The effector ...

What is an effector process? The effector process is a method that verifies itself.The effector process exists in particular criteria.

Define logical address and physical address, Define logical address and phy...

Define logical address and physical address. An address formed by the CPU is referred as logical address. An address seen by the memory unit that is the single loaded into the

Define dynamic loading, Define dynamic loading. To obtain better memory...

Define dynamic loading. To obtain better memory-space utilization dynamic loading is used. With dynamic loading, a routine is not loaded until it is called. All routines are ke

PSEUDO CODE FOR PROGRAM, THE PROGRAM WILL CHOOSE TWO RANDOM NUMBERS,THEN PR...

THE PROGRAM WILL CHOOSE TWO RANDOM NUMBERS,THEN PRINT THEM OUT AS AN ADDITION PROBLEM.THE PROGRAM WILL THEN ASK THE USERTO ENTER THE CORRECT ANSWER.IF THE ANSWER IS CORRECT,THE PRO

List three ways of allocating storage, List three ways of allocating storag...

List three ways of allocating storage, and give advantages of each. a. Contiguous allocation. Fastest, if no changes are to be made. Also simplest for random access files. b

Explain the sleep (ms) function, Explain the Sleep (ms) Function  This ...

Explain the Sleep (ms) Function  This call places the current thread in a suspended state for the number of milliseconds passed as the parameter (ms). After that Windows NT wil

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