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
Explain the Proper Distribution of Functionality and Code It is important to note that the bandwidth of the server operating system and server processor availability is fixed.


Normal 0 false false false EN-IN X-NONE X-NONE MicrosoftInternetExplorer4

Q. Name two differences between logical and physical addresses? Answer: A logical address doesn't refer to an actual existing address rather it refers to an abstract address in

Making the Transition to Client - Server Programming Making the transition to client - server programming is a significant effort. Client - server applications must be designed

What is sector sparing is proper definition

Q. Illustrate the function of Loader? A loader is a routine which loads an object program and prepares it for execution. There are many loading schemes: relocating, absolute an

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

Synchronization In communication among processes messages passed may be blocking or nonblocking - also called as synchronous and asynchronous. Blocking send : The sending pr

function of lazy swapper