1 / 8

Concurrency Challenges: The Milk Dilemma in Roommate Dynamics

In a humorous exploration of concurrency issues, two roommates, A and B, face the familiar struggle of managing milk supplies. Both arrive home to find an empty fridge, leading them to embark on a synchronized mission to buy milk. As they navigate the complexities of threading, notes, and the frustrating "too much milk" scenario, their attempts to avoid duplicate purchases create chaotic yet comedic outcomes. This situation serves as a playful metaphor for cooperation and resource management within concurrent systems, a core concept in computer science.

raisie
Télécharger la présentation

Concurrency Challenges: The Milk Dilemma in Roommate Dynamics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

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

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

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

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

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

  8. CS 140 Lecture Notes: Concurrency

More Related