CS 140 Lecture Notes: Concurrency

Slides:



Advertisements
Similar presentations
Synchronization NOTE to instructors: it is helpful to walk through an example such as readers/writers locks for illustrating the use of condition variables.
Advertisements

Threads and Critical Sections Thomas Plagemann Slides from Otto J. Anshus, Tore Larsen (University of Tromsø), Kai Li (Princeton University)
Process Synchronization A set of concurrent/parallel processes/tasks can be disjoint or cooperating (or competing) With cooperating and competing processes.
First steps  First get out a mug from your cupboard.  Next pour cold water into your kettle.  Then press the button and wait for it to boil.
CS 140 Lecture Notes: ConcurrencySlide 1 Too Much Milk Person A 3:00Arrive home: no milk 3:05Leave for store 3:10Arrive at store 3:15Leave store 3:20Arrive.
CS 140 Lecture Notes: ConcurrencySlide 1 Too Much Milk Person A 3:00Arrive home: no milk 3:05Leave for store 3:10Arrive at store 3:15Leave store 3:20Arrive.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
Threads and Critical Sections Vivek Pai / Kai Li Princeton University.
Synchronization Andy Wang Operating Systems COP 4610 / CGS 5765.
Concurrency Recitation – 2/24 Nisarg Raval Slides by Prof. Landon Cox.
Autumn, 2014C.-S. Shieh, EC, KUAS, Taiwan1 智慧電子應用設計導論 (1/3) Audio Chin-Shiuh Shieh ( 謝欽旭 ) Department of Electronic Engineering.
9/8/2015cse synchronization-p1 © Perkins DW Johnson and University of Washington1 Synchronization Part 1 CSE 410, Spring 2008 Computer Systems.
1 Lecture 9: Synchronization  concurrency examples and the need for synchronization  definition of mutual exclusion (MX)  programming solutions for.
1 Thread Synchronization: Too Much Milk. 2 Implementing Critical Sections in Software Hard The following example will demonstrate the difficulty of providing.
Industrial Revolution Lecture pt. II Transitions in the Manufacturing of Goods.
Chinese New Year Wendy Osteyee-Christensen. We welcome in the New Year as we welcome the spring. Five days of feasting. Five days with family Five days.
onions aubergines nutsrice The first and second group will search through the internet about countable and uncountable nouns using the following.
Snow!. Snowball Snowman Snow fort One piece of snow: Snowflake.
Walking between home and school. Leaving home in the morning on your walk to school.
11/18/20151 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC Based on slides by Roy Campbell, Sam.
CS 160 Lecture 4 Martin van Bommel. Overflow In 16-bit two’s complement, what happens if we add =
CPS110: Thread cooperation Landon Cox. Constraining concurrency  Synchronization  Controlling thread interleavings  Some events are independent  No.
Today’s lecture Review chapter 5 go over exercises.
Implementing Lock. From the Previous Lecture  The “too much milk” example shows that writing concurrent programs directly with load and store instructions.
Midterm exam Info IAT106 Spring 2016
Concurrency: Locks and synchronization Slides by Prof. Cox.
Christmas in America. Christmas Christmas is December 25 th. Christmas has 2 purposes. Christmas is a holiday to celebrate Jesus’ birthday. (religious)
6/27/20161 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC Based on slides by Roy Campbell, Sam King,
29 June 2015 Charles Reiss CS162: Operating Systems and Systems Programming Lecture 5: Basic Scheduling + Synchronization.
Daily Fix-It please put the cup hear. try knot to spill it.
CS703 – Advanced Operating Systems
Word Problems Dividing!.
COMPSCI210 Recitation 12 Oct 2012 Vamsi Thummala
Fry Instant Sight Words
Sight words mp1 Words 1-75.
Parallel Architectures
Too Much Milk With Locks
Too Much Milk With Locks
Andy Wang Operating Systems COP 4610 / CGS 5765
Adding MLA Format Page Numbers to a Word Document
CS 140 Lecture Notes: Concurrency
CS 140 Lecture Notes: Concurrency
Too Much Milk With Locks
FIRST GRADE SIGHT WORDS
Too Much Milk With Locks
Too Much Milk With Locks
In partnership with Week 38 Design & Technology Y2X3
Get.
Arrivals09:41 Please do not leave your baggage unattended.
slides adapted from Marty Stepp and Hélène Martin
The Second One Hundred Sight Words
Implementing Mutual Exclusion
First Grade High Frequency Words
CS 140 Lecture Notes: Introduction
(Put name of subject, chapter, topic, etc. HERE)
Implementing Mutual Exclusion
STORE MANAGER RESPONSIBILITIES.
CS 140 Lecture Notes: Concurrency
CS 140 Lecture Notes: Introduction
How to find the nth rule for a linear sequence
Presentation Title Presenter’s Name.
So different.
Lecture 20: Synchronization
over know only new place little new place little sound years work
1984 Presentation Put your topic here.
Fry Words The Second Hundred.
Goals Design decisions Design Insertion
Too Much Milk With Locks
[HOST], [LOCATION] [DATE]
Don Porter Portions courtesy Emmett Witchel
Presentation transcript:

CS 140 Lecture Notes: Concurrency 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

CS 140 Lecture Notes: Concurrency Too Much Milk Roommate A Roommate 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

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

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

CS 140 Lecture Notes: Concurrency 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

CS 140 Lecture Notes: Concurrency 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

CS 140 Lecture Notes: Concurrency 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