Example of producer consumer - semaphore, Operating System

Now let's implement bounded producer-consumer with semaphores, a Coke machine which is initially empty:

semaphore sem_mutex = 1 // binary semaphore for mutual exclusion, 1==unlocked

semaphore slots_left = N
semaphore cokes_left = 0
insert Coke into machine
buy Coke

Note that the down(slots left) needs to go before the down(sem mutex), and similarly for down(cokes left) and down(sem mutex), because otherwise the system can end up waiting forever. For example, imagine an empty machine with the consumer arriving ?rst, and calling down(sem mutex) before down(cokes left).

In some sense, the consumer calling down(cokes left) is a reservation to get a Coke in the future. Even if there are no Cokes currently in the machine, the consumer is reserving a claim for a future Cokewith this action. Similarly, the producer calling down(slots left) is a reservation to insert a new Coke in the future.

Posted Date: 3/12/2013 5:24:48 AM | Location : United States

Related Discussions:- Example of producer consumer - semaphore, Assignment Help, Ask Question on Example of producer consumer - semaphore, Get Answer, Expert's Help, Example of producer consumer - semaphore Discussions

Write discussion on Example of producer consumer - semaphore
Your posts are moderated
Related Questions
There is a very small amount of networking background required for Project 2. In Project 2, we want our computer (or our "host") to request information over the Internet from a rem

What are the various categories of software?  System software Application  software Engineering/Scientific software Embedded software  Web Applications Artificial I

Q. Regard as a logical address space of eight pages of 1024 words every mapped onto a physical memory of 32 frames. a. How several bits are there in the logical address? b. H

what is difference between file descriptor and file pointer?

What is graceful degradation? In multiprocessor systems, failure of single processor will not halt the system, but only slow it down by sharing the work of failure system by ot

Q. Define the difference among pre-emptive and non pre-emptive scheduling. Answer: Pre-emptive scheduling permits a process to be interrupted in the midst of its execution ta

What do you understand by “line balancing”? What happens if balance doesn’t exist?

Cold Backup: It is copying the three groups of files when the object is shut down. This is a straight file copy, generally from the storage disk directly to tape. You must end th

. A paper mill produces two grades of paper viz., X and Y. Because of raw material restrictions, it cannot produce more than 400 tons of grade X paper and 300 tons of grade Y paper

A working Ubuntu Linux operating system.  You can use a Live-CD to complete this assignment. Create an empty text file named assignment6.txt in your home directory. Edit this