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
Q. What is the major advantage of the layered approach to system design? What are the de-merits of using the layered approach? Answer: As in all cases of modular design as well

Explain Busy Waiting Semaphores Weak, Busy-wait Semaphores a) The simplest way to implement semaphores. b) Useful while critical sections last for a short time, or we com


KERNEL ACTIVITY FOR ULTS: The kernel isn't aware of thread activity but it is still managing process activity. When a thread compose a system call the whole process will be bl

with the aid of diagrams describe the following OS structure monolithic,layered and client server.

Determining the time quantum for a job is a critical task. Given the assumptions that the average switching time between processes is s, and the average amount of time an I/O bo

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

We can view an operating system as a resource allocator. Explain. We can outlook an operating system as a resource allocator. A computer system has Many resources (software and

Define deadlock. A process requests resources; if the resources are not available at that time, the process enters a wait state. Waiting processes might be never again change s

Q. Explain the differences in terms of cost between the three storage types nonvolatile, volatile and stable. Answer: Volatile storage refers to main as well as cache memory an