CLAUS BRABRAND © CONCURRENCY (Q3,’07) FEB 05, 2007 CONCURRENCY Claus Brabrand [email protected] [ http://www.daimi.au.dk/~brabrand/ ]
Dec 18, 2015
CLAUS BRABRAND © CONCURRENCY (Q3,’07) FEB 05, 2007
CONCURRENCY
Claus [email protected]
[ http://www.daimi.au.dk/~brabrand/ ]
CLAUS BRABRAND © CONCURRENCY (Q3,’07) FEB 05, 2007
WELCOME !
CLAUS BRABRAND[ 3 ]
© CONCURRENCY (Q3,’07) FEB 05, 2007
Agenda (Course Presentation)
Course Presentation: Weekly schedule Aims & goals Exam & assessment Roles: students & teachers Motivation: ”Why bother learning about Concurrency!?!” Materials (book & notes)
Week 1: ”Processes and Threads” Concepts Models (FSP) Practice (Java) Models (FSP) (Java) Practice
CLAUS BRABRAND[ 4 ]
© CONCURRENCY (Q3,’07) FEB 05, 2007
Weekly Schedule
Lectures: Mondays 11:15-14:00 (sometimes a bit less)
Theoretical Exercise Classes (aka. “TØ”): Tuesdays 08:15-10:00 [ shannon.164 ]
Practical Programming Labs (aka. “Lab”): Thursdays 10:15-12:00 [ zuse.127 ]
Studying: Exercises, Reading, and Thinking(!)
Compulsory homework: Hand-ins (Sunday deadlines), Mini-project
3 hrs/week
2 hrs/week
2 hrs/week
? hrs/week
? hrs/week
Expected total: 15 hrs/week
CLAUS BRABRAND[ 5 ]
© CONCURRENCY (Q3,’07) FEB 05, 2007
Course Aims & Goals
YourAims & Goals:
at huske udenad… at identificere brug af concurrency i (Java) programmer; at beskrive concurrency mekanismer i programmeringssprog (Java); at forklare fundamentale problemer, teknikker og løsninger indenfor concurrency; at forklare sammenhængen mellem modeller og programmer generelt; at relatere konkrete modeller og programmer; at sammenligne konkrete modeller; at ræsonnere om egenskaber af konkrete modeller og programmer; at implementere konkrete modeller i programmeringssprog (Java); at anvende ovenstående med henblik på at skabe konkrete modeller af systemer.
CLAUS BRABRAND[ 6 ]
© CONCURRENCY (Q3,’07) FEB 05, 2007
Exam Eksamenerne er konstrueret til at evaluere din dybdeforståelse af
concurrency i overensstemmelse med dine mål (se ovenfor).
Jo bedre du kan ovenstående mål, jo bedre vil du klare dig til eksamen; du vil således kunne bruge målene overfor dig selv som en checkliste for din egen forståelse. Som en direkte konsekvens heraf vil der ikke være hverken "type"- eller "huske"-opgaver (som ikke nødvendigvis forudsætter dybdeforståelse).
Eksamen: 13-skala karakter på baggrund af: (gruppe) mini-projektet samt (individuel) multiple-choice prøve
...som begge vil være centreret omkring ovenstående mål
NB: For at blive indstillet til eksamen, skal alle afleveringsopgaver være afleveret - og godkendt.
CLAUS BRABRAND[ 7 ]
© CONCURRENCY (Q3,’07) FEB 05, 2007
Concurrency: Aims & Goals Exam
Motivation Roles Program Project Exam Materials Classes Webboard
Homepage [ http://www.daimi.au.dk/~brabrand/concurrency/ ]
CLAUS BRABRAND © CONCURRENCY (Q3,’07) FEB 05, 2007
YOUR ROLE
Active Learning (!)
CLAUS BRABRAND[ 9 ]
© CONCURRENCY (Q3,’07) FEB 05, 2007
Consider the following “alphabet” (60 secs):
Exercise: Now write my office phone#: 89425771 ?
Exercise 1
1. 2. 3. 4. 5.
6. 7. 8. 9. 0.
CLAUS BRABRAND[ 10 ]
© CONCURRENCY (Q3,’07) FEB 05, 2007
Exercise 1 (cont’d)
Suppose I now showed you…:
Exercise: Now write my office phone#: 89425771 ?
1 2 3
4 5 6
7 8 9
CLAUS BRABRAND[ 11 ]
© CONCURRENCY (Q3,’07) FEB 05, 2007
Exercise 1 (cont’d)
So what is the point? Random information is really hard to remember We learn (efficiently) by associating (building)
new unknown information / with (on) old known information
Knowledge is constructed as a result of: Learner’s activity (!)
In short: “You need to study”: i.e. read, make exercises, and think(!)
CLAUS BRABRAND © CONCURRENCY (Q3,’07) FEB 05, 2007
COLLABORATION
Teaching / Learning Collaboration
CLAUS BRABRAND[ 13 ]
© CONCURRENCY (Q3,’07) FEB 05, 2007
Roles (Teaching/Learning Collaboration)
During learning period (i.e., before the exam): Teaching/Learning collaboration:
You = “Learner” Learning responsibility
Me = “Teacher” (and Teaching Assistant) (To the best of my ability) aid you in learning
During the exam period: You = “Performer”
Demonstrate what you have learned
Me = “Evaluator” (Neutrally) assess your level of understanding
CLAUS BRABRAND © CONCURRENCY (Q3,’07) FEB 05, 2007
MOTIVATION
“Why bother learning about Concurrency?!?”
CLAUS BRABRAND[ 15 ]
© CONCURRENCY (Q3,’07) FEB 05, 2007
What is a Concurrent Program?
A sequential program has a single thread of control
A concurrent program has multiple threads of control:
Perform multiple computations in parallel Control multiple external activities which
occur at the same time
CLAUS BRABRAND[ 16 ]
© CONCURRENCY (Q3,’07) FEB 05, 2007
Why Concurrent Programming? More appropriate program structure
Concurrency reflected in program
Performance gain from multiprocessing HW Parallelism
Increased application throughput An I/O call need only block one thread
Increased application responsiveness High-priority thread for user requests
CLAUS BRABRAND[ 17 ]
© CONCURRENCY (Q3,’07) FEB 05, 2007
Concurrency vs. Sequentiality
Sequential programming: Inherently deterministic Describe computation as a “reduction” of expressions to values Termination often desirable Resulting value is of primary interest and focus
Concurrent programming: Inherently non-deterministic Describe execution as “process evolution” Describe possible executions (aka. execution traces) Describe possible interactions during execution Describe interaction with an environment Non-termination often desirable (e.g. Op.Sys., Control sys, Cell-phone, …) Resulting “value” is not (necessarily) interesting
CLAUS BRABRAND[ 18 ]
© CONCURRENCY (Q3,’07) FEB 05, 2007
Concurrency is much Harder
Harder than sequential programming: Huge number of possible executions Inherently non-deterministic Parallelism conceptually harder
Consequences: Programs are harder to write(!) Programs are harder to debug(!) Errors are not always reproducible(!) New kinds of errors possible(!):
Deadlock, starvation, priority inversion, interference, …
CLAUS BRABRAND[ 19 ]
© CONCURRENCY (Q3,’07) FEB 05, 2007
Example Concurrency Problems
Therac-25 Radiation Therapy ’85-’87
Massive overdoses (6 deaths / amputations)!
Mars Pathfinder July ’97
Periodic resets
Win95/98 w/ 3rd-Party Device Drivers late ’90es
Dysfunction (“blue screen of death”)!
...on mars!
CLAUS BRABRAND[ 20 ]
© CONCURRENCY (Q3,’07) FEB 05, 2007
Concurrency Problems (cont’d)
Mobile Phones ’00-…
Freeze and odd behaviors (really annoying)!
Cruise Control System Model ’86 [Grady Booch]
Accellerated after car ignition (car crashes)!
CLAUS BRABRAND[ 21 ]
© CONCURRENCY (Q3,’07) FEB 05, 2007
…and what about?
Air Plane Control System
Dysfunction (plane crash)!
Nuclear Powerplant Control System
Core melt-down (“China-syndrome”)!
…
CLAUS BRABRAND[ 22 ]
© CONCURRENCY (Q3,’07) FEB 05, 2007
Problem: System Development?
In the presence of all these errors: deadlock, starvation, priority inversion, interference,
anti-cooperation, un-intended execution traces, un-fairness, …
How to…: 1. …design a system that “works” ? 2. …verify that the system is “safe” ? 3. …verify that the system “meets its specification” ?
…and: What does “works”, “safe”, and “to meet a specification” mean ?!?
CLAUS BRABRAND[ 23 ]
© CONCURRENCY (Q3,’07) FEB 05, 2007
Solution: Modeling
“Models come to the rescue”: Create models (~ architecture, bridge construction, …)
Formal modeling (e.g., “FSP”) permits: (Offline) Reasoning understanding (Runtime) Testing confidence (C-time) Property Verification safety (C-time) Specification Verification correctness
Note: “Errors are much cheaper to commit in models than in implementations”
“Never send a human to do a machine’s job”-- A.Smith (’99)
auto-mate
CLAUS BRABRAND[ 24 ]
© CONCURRENCY (Q3,’07) FEB 05, 2007
Methodology: Model-based Design
Design abstract model
Decompose model
Reason/Test/Verify model individual parts and whole
Recompose insights make model safe
Impl. concrete program
concretize
REAL PROBLEM
SAFE MODEL
SAFE PROGRAM
abstract
? ?
?
?
MODEL
testreason
verify
CLAUS BRABRAND[ 25 ]
© CONCURRENCY (Q3,’07) FEB 05, 2007
Program worldModel world
ConcreteAbstract
P Mabstraction
concretization
Program vs. Model World
(Java) (FSP)
What discerns a really good programmer from one that is not so good is the capability of moving (consciously or unconsciously) between the concrete world of programs and the abstract world of semantic models (via abstraction and concretization).
Specifically, such a programmer is capable of (consciously or unconsciously): - 1) abstracting programs into models - 2) reasoning about the models - 3) concretizing the insights back into the world of programs
CLAUS BRABRAND[ 26 ]
© CONCURRENCY (Q3,’07) FEB 05, 2007
Program worldModel world
ConcreteAbstract
P M
1. P ? 3. M ?
4. validate
5. M !7. P !
2. abstract
6. concretize
Program / Model Verification
(Java) (FSP)
CLAUS BRABRAND[ 27 ]
© CONCURRENCY (Q3,’07) FEB 05, 2007
Program worldModel world
ConcreteAbstract
~
P
P’
M
M’
1. P ~ P’ ?2. abstract
3. M ~ M’ ?
4. relate
5. M ~ M’ !6. concretize7. P ~ P’ !
Program / Model Relationship
(Java) (FSP)
CLAUS BRABRAND[ 28 ]
© CONCURRENCY (Q3,’07) FEB 05, 2007
Glasses of Abstraction…
It’s Amazing…
Abstract away computational details: see only concurrency aspects
at appropriate level of abstraction!
Only$12,95
“See only the relevant!”
“The Glasses of Abstraction”
COMPLEX PROGRAMCOMPLEX PROGRAM
MODELMODEL
abstraction
CLAUS BRABRAND[ 29 ]
© CONCURRENCY (Q3,’07) FEB 05, 2007
Modeling: Level of Abstraction
Consider a client/server system:
Extremely abstract (high level of abstraction):
Appropriate (level of abstraction) for … :
Extremely concrete (low level of abstraction):
System = (event -> System).
NAND_Gate = ...Transistor = ...Accumulator = ......Client = ...
Server = (request->compute->reply->Server).Client = (calc->request->wait->reply->Client).Database = ...
high
er le
vel o
f ab
stra
ctio
n
CLAUS BRABRAND[ 30 ]
© CONCURRENCY (Q3,’07) FEB 05, 2007
Notes on Skill Acquisition
Your skill acquisition will progress according to the following stages of learning:
4. Unconscious competence 3. Conscious competence 2. Conscious incompetence 1. Unconscious incompetence
Course aim (and measurement): Level 3 Later in life, you probably mostly need level 4
…but you need to get there via level 3
CLAUS BRABRAND[ 31 ]
© CONCURRENCY (Q3,’07) FEB 05, 2007
Modeling Language (e.g. “FSP”)
Compositional: ||
Break things into (several) smaller things
Algebraic: ,
Intuitive ideal and eases automated verification
Syntactic:
Provide basis for programming languages
P || Q P Q
big
P || Q Q || P P || (Q || R)
USER =def (acquire -> use -> release -> USER).
(P || Q) || R
CLAUS BRABRAND[ 32 ]
© CONCURRENCY (Q3,’07) FEB 05, 2007
Parallel- vs. Concurrent Programming
Strategy: Optimal strategy for a particular goal Use available resources efficiently
Safety: Conceptually independent players Control interaction and “rules”
The Football Match Analogy:“An analogy that one can make is with football*; - the coach of the team is a parallel programmer while - the referee is a concurrent programmer” -- [P.Panangaden, ’96]
The Referee (~ the concurrent programmer):-- Make sure what is happening is a soccer match
The Trainer (~ the parallel programmer):-- Make sure my agents are performing “optimally”
*/ interpret appropriately on either side of the Atlantic
CLAUS BRABRAND[ 33 ]
© CONCURRENCY (Q3,’07) FEB 05, 2007
Course Aims & Goals
YourAims & Goals:
at huske udenad… at identificere brug af concurrency i (Java) programmer; at beskrive concurrency mekanismer i programmeringssprog (Java); at forklare fundamentale problemer, teknikker og løsninger indenfor concurrency; at forklare sammenhængen mellem modeller og programmer generelt; at relatere konkrete modeller og programmer; at sammenligne konkrete modeller; at ræsonnere om egenskaber af konkrete modeller og programmer; at implementere konkrete modeller i programmeringssprog (Java); at anvende ovenstående med henblik på at skabe konkrete modeller af systemer.
T