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
How exactly is a page table used to look up an address? The CPU has a page table base register (PTBR)which points to the base (entry 0) of the level-0 page table. Each process h

What is reference string We evaluate an algorithm by running it on a definite string of memory reference and computing the number of page faults. The string of memory reference

Q. Operating System as User Interface? • Every general purpose computer comprises the operating system, hardware, system programs and application programs. The hardware compris

? FREE ASSOCIATION ASSIGNMENTS of multiprograming

Consider the subsequent resource-allocation policy. Requests as well as releases for resources are allowed at any time. If a request for resources can't be satisfied because the re

Question: a) Each process is represented in the operating system by a process control block (PCB). The PCB contains many pieces of information associated with a specific proce

Question: (a) Answer the following questions based on the code snippet below. 1. int main (int argc, char *argv[]) 2. { 3. 4. pid_t processId; 5. 6. processId =

The term IPC (Inter-Process Communication) defines several paths by which different process executing on some operating system interact between each other.


Explain Wait for Graph a. Use a resource allocation graph to derive a wait-for graph.  b. Wait-for graph acquired by making an edge from p 1 to p 2 iff p 1 is waiting for