1 / 8

Too Much Milk

Too Much Milk. Person 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. Too Much Milk. Person A Person B 3:00 Arrive home: no milk 3:05 Leave for store 3:10 Arrive at store Arrive home: no milk

rock
Télécharger la présentation

Too Much Milk

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 Person 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 Person A Person 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 if (!GotMilk) { if (NoNote) { Leave Note; Buy Milk; Remove Note; } } CS 140 Lecture Notes: Concurrency

  4. Still Too Much Milk Thread A: Thread B: if (!GotMilk) { if (NoNote) { if (!GotMilk) { if (NoNote) { Leave Note; Buy Milk; Remove Note; } } Leave Note; Buy Milk; Remove Note; } } CS 140 Lecture Notes: Concurrency

  5. Thread A: if (NoNote) { if (!GotMilk) { Buy Milk; } Leave Note; } Thread B: if (Note) { if (!GotMilk) { Buy Milk; } Remove Note; } Second Attempt CS 140 Lecture Notes: Concurrency

  6. Thread A: 1 Leave NoteA; 2 if (No NoteB) { 3 if (!GotMilk) { 4 Buy Milk; 5 } 6 } 7 Remove NoteA; Thread B: 1 Leave NoteB; 2 if (No NoteA) { 3 if (!GotMilk) { 4 Buy Milk; 5 } 6 } 7 Remove NoteB; Third Attempt CS 140 Lecture Notes: Concurrency

  7. Thread A: 1 Leave NoteA; 2 if (No NoteB) { 3 if (!GotMilk) { 4 Buy Milk; 5 } 6 } 7 Remove NoteA; Thread B: 1 Leave NoteB; 2 while (NoteA) { 3 do nothing 4 } 5 if (!GotMilk) { 6 Buy Milk; 7 } 8 Remove NoteB; Fourth Attempt CS 140 Lecture Notes: Concurrency

  8. CS 140 Lecture Notes: Concurrency

More Related