DOC PREVIEW
Stanford CS 140 - Lecture Notes

This preview shows page 1-2-3 out of 8 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Too Much MilkToo Much MilkComputerized Milk PurchaseStill Too Much MilkSecond AttemptThird AttemptFourth AttemptSlide 8CS 140 Lecture Notes: Concurrency Slide 1Too Much MilkPerson A3:00 Arrive home: no milk3:05 Leave for store3:10 Arrive at store3:15 Leave store3:20 Arrive home, put milk awayCS 140 Lecture Notes: Concurrency Slide 2Too Much MilkRoomate A Roomate B3:00 Arrive home: no milk3:05 Leave for store3:10 Arrive at store Arrive home: no milk3:15 Leave store Leave for store3:20 Arrive home, put milk away Arrive at store3:25 Leave store3:30 Arrive home: too much milk!CS 140 Lecture Notes: Concurrency Slide 3Computerized Milk Purchaseif (milk == 0) { if (note == 0) { note = 1; buyMilk(); note = 0; }}CS 140 Lecture Notes: Concurrency Slide 4Still Too Much MilkThread A: Thread B:if (milk == 0) { if (note == 0) {if (milk == 0) { if (note == 0) { note = 1; buyMilk(); note = 0; }} note = 1; buyMilk(); note = 0; }}CS 140 Lecture Notes: Concurrency Slide 5Second AttemptThread A:if (note == 0) { if (milk == 0) { buyMilk(); } note = 1;}Thread B:if (note == 1) { if (milk == 0) { buyMilk(); } note = 0;}CS 140 Lecture Notes: Concurrency Slide 6Third AttemptThread A:1 noteA = 1;2 if (noteB == 0) {3 if (milk == 0) {4 buyMilk();5 } 6 }7 noteA = 0;Thread B:1 noteB = 1;2 if (noteA == 0) {3 if (milk == 0) {4 buyMilk();5 } 6 }7 noteB = 0;CS 140 Lecture Notes: Concurrency Slide 7Fourth AttemptThread A:1 noteA = 1;2 if (noteB == 0) {3 if (milk == 0) {4 buyMilk();5 } 6 }7 noteA = 0;Thread B:1 noteB = 1;2 while (noteA == 1) {3 // do nothing4 }5 if (milk == 0) {6 buyMilk();7 } 8 noteB = 0;CS 140 Lecture Notes: Concurrency Slide


View Full Document

Stanford CS 140 - Lecture Notes

Documents in this Course
Homework

Homework

25 pages

Notes

Notes

8 pages

Load more
Download Lecture Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?