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. Regard as a logical address space of eight pages of 1024 words every mapped onto a physical memory of 32 frames. a. How several bits are there in the logical address? b. H

Q. Present an algorithm for reconstructing a logical ring after a process in the ring fails? Answer: Typically distributed systems utilize a coordinator process that performs

ADVANTAGES AND INCONVENIENCES OF KLT Advantages: the kernel be able to simultaneously schedule many threads of the same process on many processors blocking

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

Q. If each the access rights to an object are deleted the object can no longer be accessed. At this stage the object should also be deleted and the space it occupies should be ret

The code should be nicely formatted with plenty of comments. It should be easy to read, properly The summary section should include three parts: (1) Record the running t

Android operating system is an open source, Linux-based Smartphone OS. It is the world's most popular mobile platform with more than 700,000 applications and 25 billion downlo

GUI - Short for Graphical User Interface a GUI Operating System contains icons and graphics and is commonly navigated by using a computer mouse. Below are some instances of GUI Op

Describe when you run an unlink() operation to remove a file on the ext3 file system. Be specific about what disk blocks have to be written where in what order. State your assumpti