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
Describe the purpose of the checkpoint mechanism. How habitually must checkpoints be performed? Explain how the frequency of checkpoints affects: System performance while no

Q. What is the basic function of Assembler ? Input to an assembler is an assembly language program. Output is an object program and information which enables the loader to prep

What lead to the concept of paging? The main memory is separated into two parts that are one for the resident operating system, and one for the user processes. We may perhaps p

Explain the Peterson's solution for the critical section problem? In Peterson's solution two variables a) flag and b) turn are used as shared variables. If the both shared vari

Explain Process scheduling Process scheduling consists of the subsequent sub-functions: 1.      Scheduling : Selects the process to be implement next on the CPU 2.      D

Demand paging With demand paging, a page is called into memory only when a location on that page is actually indexed during run time. With pre-paging, pages other than the one

Processes- Making the System More Responsive and Useful A method by definition build up of a code execution and resource ownership. A process has two main characteristics, code

Explain the Application Interaction Protocols Application interaction protocols are uniquely defined for each program and are used to logically describe the data being passed b

File System Interface and Implementation The Nachos file system, as distributed, uses a single-level index allocation method for data allocation of files. In the current design,

What do you mean by first fit? First fit allocates the first hole that is big sufficient .Searching can either start at the starting of the set of holes or where the previous f