Question: in C language Exercise 14.3.17: Consider two roommates who share a refrigerator and who-as conscientious roommates ensure the refrigerator is always stocked with only one

in C language
 in C language Exercise 14.3.17: Consider two roommates who share a

Exercise 14.3.17: Consider two roommates who share a refrigerator and who-as conscientious roommates ensure the refrigerator is always stocked with only one bottle of milk. However, even with such kind room- mates, the following problematic scenario is possible: Roommate 1's actions Roommate 2's actions 3:00 Look in fridge; out of milk. 3:05 Leave for market. 3:10 Arrive at market. 3:15 Buy milk 3:20 Arrive home; put milk in fridge. 3:25 3:30 3:35 Look in fridge; out of milk. Leave for market. Arrive at market. Buy milk. Arrive home; put milk in fridge. Sigh "Oh no!" Write a complete Go program to solve this problem i.e., to eliminate the race condition above) without busy waiting. Your main function will spawn only two goroutines. Do not give more than 25 lines of code

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!