Describe the given program

Assignment Help Computer Engineering
Reference no: EM131476321

Question: For the solution to Too Much Milk suggested in the previous problem, each call to drinkMilkAndBuyIfNeeded() is atomic and holds the lock from the start to the end even if one roommate goes to the store. This solution is analogous to the roommate padlocking the Kitchen while going to the store, which seems a bit unrealistic. Implement a better solution to drinkMilkAndBuyIfNeeded () using both locks and condition variables. Since a roommate now needs to release the lock to the kitchen while going to the store, you will no longer acquire the lock at the start of this function and release it at the end. Instead, this function will call two helper-functions, each of which acquires/releases the lock. E.g.,

int

Kitchen : : drinkMilkAndBuyIfNeeded(){

        int     iShouldBuy = waitThenDrink();

        if (iShouldBuy){

              buyMilk();

        }

}

In this function, waitThenDrink() should (if there is no milk) wait (using a condition variable) until there is milk, drink the milk, and if the milk is now gone, return a nonzero value to flag that the caller should buy milk. BuyMilk() should buy milk and then broadcast to let the waiting threads know that they can proceed. Again, test your code with varying numbers of threads.

Reference no: EM131476321

Questions Cloud

Discuss the process of strategy formulation : Discuss the process of strategy formulation. How can TQ improve this process? In the hindsight what were the main reasons for CareGroup’s network outage?
Illustrate various changes have on demand and supply : Illustrate in the form of diagrams, the effects, various changes have on demand and supply of a particular good or service and explain briefly your diagrams.
Compose a function : Compose a function (that_string.py) that takes as argument three arrays of strings, determines whether there is any string common.
Proper requirements engineering activities : 1. What are some of the major objections and deterrents to proper requirements engineering activities?
Describe the given program : For the solution to Too Much Milk suggested in the previous problem, each call to drinkMilkAndBuyIfNeeded() is atomic and holds the lock from the start.
Find a study whose statistical results have been published : Are there any problems in defining or measuring the variables of interest in the study?Are there any confounding variables present in the study?
Companies commonly tag each of their active customers : Explain two (2) ways companies commonly tag each of their active customers.
Explaining the most common security threats : Create a 10-slide presentation explaining the most common security threats, modern threats to current Client and Server Operating Systems, Encryption.
Calculate the marginal product of labor function : Calculate the marginal product of labor function when K=9. Calculate the average product of labor function when K=9.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd