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

  Describe briefly how input devices are tested

Explain why a safety circuit or other EMERGENCY STOP device is important.

  Design an application that it will prompt a user

You will need to design an application that it will prompt a user for their hourly pay rate, their hours worked, and whether they are single, married, divorced, or widowed.

  64-bit architecture

How would you design software to do this (Use a maximum of one to two paragraphs of 5-7 sentences each)?

  Change asynchronous-clear to a synchronous-clear circuit

Change the asynchronous-clear circuit to a synchronous-clear circuit in the register of Figure. The modified register will have a parallel-load capability and a synchronous-clear capability.

  How many tasks real-time application contain

How many tasks real-time application contain In this particular real-time application, there are many tasks; each runs exact same code except with different data each time.

  Merging using this process

Merging is the mehood of combining two sorted lists into a single sorted list. In some cases, one list can be appended to the other, and the new list then can be sorted. Merging using this method, though, is not always the most efficient.

  Pseudorandom numbers

In any use of the pseudorandom numbers, whether for the encryption, simulation or the statistical design.

  Describe the arp process

What is a ARP Request and ARP Reply?What is the broadcast.

  When the first request arrives in the disk request queue

As in our previous question, when the first request arrives in the disk request queue, the read/write head is at track 50, moving toward the outer (lower-numbered) tracks.

  Explain the use of pipelining in computer architecture

Using your learning materials and your own research, you will outline the principles of pipelining and explain the use of pipelining in computer architecture.

  Recognize how to locate fsmo roles

Recognize how to locate FSMO roles?

  Describe the memory and paging sim

Your goal here is to use the simulators to understand these different types of memory caches. To do this, you need to run each type of simulator and document/explain what it is doing. For the three the cache simulators, you need to compare and con..

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