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
Determine the equation for the y and truth table for the circuits

Problem: (a) (i) Explain what a single system image is and how it is related to the concept of a distributed operating system? (ii) What are the main differences between a

Q. Presume that you have a page-reference string for a process with m frames (initially all empty). The page-reference string has length p along with n distinct page numbers


Linked list allocation: At this time the blocks are stored using linked lists. The block size require not be the same. Thus internal fragmentation is avoided. Consider

Explain the various page replacement strategies. Page replacement-basic scheme with diagram Optimal page replacement LRU page replacement FIFO page replacement LRU

Q. Distinguish among PCS and SCS scheduling. Answer: PCS scheduling is completed local to the process. It is how a thread library schedules threads onto available LWPs. SCS sch

Q. Polling for an I/O completion is able to waste a large number of CPU cycles if the processor iterates a busy-waiting loop several times before the I/O completes. However if the

What are the three main purposes of an operating system? _ To give an environment for a computer user to implement programs on computer hardware in a convenient and efficient m

What are the various file operations? The six basic file operations are Creating a file Reading a file Writing a file Repositioning within a file Tr