Producer-consumer using condition variables, Operating System

Now let us present an implementation of a producer-consumer system using condition variables. This implementation works.

dequeue()

lock(A)

while (queue empty) {
wait(A, C) // atomically releases lock A and sleeps, waiting for
// condition variable C.
// When the thread wakes up, it re-acquires the lock.
// C is the condition variable that means ''queue not empty''.
}

remove_item()
unlock(A)
enqueue()
lock(A)
insert_item()
signal(C)
unlock(A)

In dequeue() above, if the thread wakes up and by chance the queue is empty, there is no problem: that's why we need the "while" loop.

Posted Date: 3/12/2013 5:17:31 AM | Location : United States







Related Discussions:- Producer-consumer using condition variables, Assignment Help, Ask Question on Producer-consumer using condition variables, Get Answer, Expert's Help, Producer-consumer using condition variables Discussions

Write discussion on Producer-consumer using condition variables
Your posts are moderated
Related Questions
importance of Operating system in modern computers. Also explain various functions & types of operating systems

what is the need-to-know principle? why is it important for a protection system to adhere to this principle?

time-stamping It is a method proposed by Lamport, used to sequencing events in a distributed machine without the use of clocks. This process is intended to order events consis

Define Server Processing with Queues The efficient server processing of client request is essential for optimized client- server applications. This process is greatly enhanced

is there any difference between the trap and interrupt??

Q. What are the major differences between operating systems for mainframe computers and personal computers? Answer: In general operating systems for batch systems have simpler

What are the methods for handling deadlocks? The deadlock problem can be dealt with in one of the three ways: a. Use a protocol to prevent or avoid deadlocks, ensuring that

Minor page fault :I f the page is loaded in memory at the time the fault is started, but is not checked in the memory management unit as being loaded in memory, then it is named a

Convert the following from hex to binary and draw it on the memory map.     RAM    = 0000 -> 00FF     EPROM = FF00  -> FFFF Answer:   0000  0000 0000  0000 (0)    RAM sta

Q. Explain about Operating System Services? An operating system offers services to programs and to users of those programs. It provided by one environment for execution of