Too Much Milk

Too Much Milk
Slide Note
Embed
Share

In a comical series of events involving roommates and a milk shortage, explore the journey from realizing a lack of milk to dealing with unexpected surplus milk. Dive into concurrency concepts through lecture notes illustrating scenarios with thread interactions and automated milk purchasing. Delve into a humorous narrative interwoven with technical discussions on coordinating tasks in a computing context.

  • Milk Shortage
  • Roommate Drama
  • Concurrency Concepts
  • Thread Interactions
  • Humorous Narratives

Uploaded on Feb 22, 2025 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Too Much Milk Roommate A Arrive home: no milk Leave for store Arrive at store Leave store Arrive home, put milk away 3:00 3:05 3:10 3:15 3:20 3:25 3:30 CS 140 Lecture Notes: Concurrency Slide 1

  2. Too Much Milk Roommate A Arrive home: no milk Leave for store Arrive at store Leave store Arrive home, put milk away Roommate B 3:00 3:05 3:10 3:15 3:20 3:25 3:30 Arrive home: no milk Leave for store Arrive at store Leave store Arrive home: too much milk! CS 140 Lecture Notes: Concurrency Slide 2

  3. Computerized Milk Purchase 1 if (milk == 0) { 2 if (note == 0) { 3 note = 1; 4 buy_milk(); 5 note = 0; 6 } 7 } CS 140 Lecture Notes: Concurrency Slide 3

  4. Still Too Much Milk Thread A: 1 if (milk == 0) { 2 if (note == 0) { 3 4 5 6 7 8 9 10 note = 1; 11 buy_milk(); 12 note = 0; 13 } 14 } Thread B: if (milk == 0) { if (note == 0) { note = 1; buy_milk(); note = 0; } } CS 140 Lecture Notes: Concurrency Slide 4

  5. Second Attempt Thread A: 1 if (note == 0) { 2 if (milk == 0) { 3 buy_milk(); 4 } 5 note = 1; 6 } Thread B: 1 if (note == 1) { 2 if (milk == 0) { 3 buy_milk(); 4 } 5 note = 0; 6 } CS 140 Lecture Notes: Concurrency Slide 5

  6. Third Attempt Thread A: 1 noteA = 1; 2 if (noteB == 0) { 3 if (milk == 0) { 4 buy_milk(); 5 } 6 } 7 noteA = 0; Thread B: 1 noteB = 1; 2 if (noteA == 0) { 3 if (milk == 0) { 4 buy_milk(); 5 } 6 } 7 noteB = 0; CS 140 Lecture Notes: Concurrency Slide 6

  7. Fourth Attempt Thread A: 1 noteA = 1; 2 if (noteB == 0) { 3 if (milk == 0) { 4 buy_milk(); 5 } 6 } 7 noteA = 0; Thread B: 1 noteB = 1; 2 while (noteA == 1) { 3 // do nothing 4 } 5 if (milk == 0) { 6 buy_milk(); 7 } 8 noteB = 0; CS 140 Lecture Notes: Concurrency Slide 7

  8. CS 140 Lecture Notes: Concurrency Slide 8

More Related Content