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
Clustered file organization A clustered file is also called a B-tree-clustered file is a tree-structured file in which records with adjacent index values are clustered toget

Explain internal fragmentation The Internal fragmentation signifies to the result of reserving a piece of space without ever intending to use it. This space is wasted that this

Briefly explain process management in Windows 2000. The Windows 2000 process manager provides for deleting, creating and using threads and processes. It has no knowledge about

Explain about threading issues? The fork and exec system calls In a multithreaded program of few UNIX systems have chosen to have two versions of fork, one that duplicates e

As a group, you may need to make some enhancements to your development server (NOT your stable server!)  It needs to be able to run the makepasswd program, which may require instal

How can an index file be used to speed up the access in direct-access files? Have an index in memory; the index gives the key and the disk location of its corresponding record.

Define FIFO Page Replacement Algorithm This policy simply eliminates pages in the order they arrived in the main memory. By using this policy we simply remove a page based upo

advantage and dis advantage of threads

explain simple segmentation