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 do we keep track of where the free pieces of memory are? One idea is to maintain a set of linked-lists of free space; each linked-list will store free chunks of some given size

What is the kernel? A more common explanation is that the OS is the one program running at all times on the computer  usually known as the kernel, with all else being applicati

Determine a processing that is not a part of Synthesis phase  Perform LC processing is not a part of Synthesis phase

what is network operating? explain about it design issues?

1. On every access, mark the page with a timestamp. Whenever we need to evict a page, we search through memory for the oldest page, the least-recently used page. But we need memory

Relative file organization A relative file is an array of fixed-length slots and the records can be inserted in the first free slot found from the beginning of the file and

ADVANTAGES OF MICROFERNEL IN YSTEM DESIGN?

Define the DosExecPgm Functions used in the OS/2 DosExecPgm (objBuffer, objLen, flags, cmdLine, env, &resultCode, execName) DosExecPgm function is designed to load an execut

explain the link between operations management and strategic planning of daily goods shop