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. Explain the Concept of Process? A process is sequential program in execution. A process states the basic unit of computation for the computer. Components of process are:


Q. We have stressed the require for an operating system to make efficient use of the computing hardware. When is it suitable for the operating system to forsake this principle and

What are kernels and what do kernels do? The kernel is a program that comprises the central core of a computer operating   system. It has entire control over everything that

FCFS (First Come, First Served) Perform operations in order requested No reordering of work queue No starvation every demand is serviced Poor performance

BENEFITS OF THREADS OVER PROCESS If implemented correctly after those threads have some advantages of (multi) processes, they take: 1. Less time to create a new thread tha


What do you mean by best fit? Best fit allocates the smallest hole that is big sufficient. The entire list has to be searched, until it is sorted by size. This strategy creates

Q. How Program execute in operating system? Program execution: Operating system loads a program in memory and executes the program. The program should be able to end its exec

Determine how Action implementing instruction’s meaning are a actually carried out   Action implementing meaning of instruction are a actually carried out Instruction executio