Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

with c language A group of housemates have a habit of buying milk for their apartment. However, they have limited fridge space, so if there

with c language image text in transcribed
A group of housemates have a habit of buying milk for their apartment. However, they have limited fridge space, so if there are more than N bottles of milk in the fridge, they wait until some milk has been consumed before buying more. However, each housemate buys milk independently, so they can end up with more milk than can fit in the fridge. This is causing problems for the housemates, and they have asked you to implement a solution. You are to implement a program that simulates the housemates buying milk. Your program should enforce the constraint that no more than N bottles of milk can be in the fridge at any time. The program should use locks to ensure that the housemates do not try to buy milk at the same time and end up with too much milk. Requirements: 1. Use any programming language to implement the program. 2. Use a lock-based solution to synchronize access to the fridge and ensure that no more than N bottles of milk are in the fridge at any time. 3. The program should simulate N housemates buying milk over a period of M minutes, with each housemate buying milk at random times during the M minute period. 4. Use a shared variable to keep track of the number of bottles of milk in the fridge. 5. Use print statements to show when a housemate is buying milk and when they are putting the milk in the fridge. 6. At the end of the simulation, print out the number of bottles of milk left in the fridge

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Programming With Visual Basic .NET

Authors: Carsten Thomsen

2nd Edition

1590590325, 978-1590590324

More Books

Students also viewed these Databases questions