mls 10/18/2015 1 don’t start with dekker’s algorithm: top-down introduction of concurrency...
TRANSCRIPT
![Page 1: MLS 10/18/2015 1 Don’t Start with Dekker’s Algorithm: Top-Down Introduction of Concurrency Michael L. Scott Multicore Programming Education Workshop 8](https://reader036.vdocument.in/reader036/viewer/2022062802/56649ed05503460f94bddc49/html5/thumbnails/1.jpg)
MLS 04/21/23 1
Don’t Start with Dekker’s Algorithm: Top-Down Introduction of
Concurrency
Michael L. Scott
Multicore Programming Education Workshop
8 March 2009
![Page 2: MLS 10/18/2015 1 Don’t Start with Dekker’s Algorithm: Top-Down Introduction of Concurrency Michael L. Scott Multicore Programming Education Workshop 8](https://reader036.vdocument.in/reader036/viewer/2022062802/56649ed05503460f94bddc49/html5/thumbnails/2.jpg)
MLS 04/21/23 2
Bottom-Up Concurrency AKA Concurrency for Wizards Usually taught in the OS course
» Dekker’s algorithm» Peterson’s algorithm» (maybe) Lamport’s bakery and fast (no contention)
locks» TAS» T&TAS» (maybe) MCS» semaphores, monitors, (maybe) CCRs
![Page 3: MLS 10/18/2015 1 Don’t Start with Dekker’s Algorithm: Top-Down Introduction of Concurrency Michael L. Scott Multicore Programming Education Workshop 8](https://reader036.vdocument.in/reader036/viewer/2022062802/56649ed05503460f94bddc49/html5/thumbnails/3.jpg)
MLS 04/21/23 3
But...
Where did the threads come from? Why do I care?
(What are they for ?) Can mere mortals make
any of this work?
![Page 4: MLS 10/18/2015 1 Don’t Start with Dekker’s Algorithm: Top-Down Introduction of Concurrency Michael L. Scott Multicore Programming Education Workshop 8](https://reader036.vdocument.in/reader036/viewer/2022062802/56649ed05503460f94bddc49/html5/thumbnails/4.jpg)
MLS 04/21/23 4
Concurrency First?
Sequentiality as a special case» See Arvind’s talk after lunch» A backlash, perhaps, against concurrency for wizards
I’m going to suggest an intermediate approach» Learn what you need when you need it» “Top-down”, but not “concurrency first”
![Page 5: MLS 10/18/2015 1 Don’t Start with Dekker’s Algorithm: Top-Down Introduction of Concurrency Michael L. Scott Multicore Programming Education Workshop 8](https://reader036.vdocument.in/reader036/viewer/2022062802/56649ed05503460f94bddc49/html5/thumbnails/5.jpg)
MLS 04/21/23 5
Suggested Principles
Integrate parallelism & concurrency into the whole curriculum
Introduce it gradually where it naturally fits Provide clear motivation and payoff at each
step Recognize that
» everybody needs benefits from multicore» many need to deal with events (concurrency)» some need to develop concurrent data structures» few need to implement synchronization mechanisms
or other race-based code
![Page 6: MLS 10/18/2015 1 Don’t Start with Dekker’s Algorithm: Top-Down Introduction of Concurrency Michael L. Scott Multicore Programming Education Workshop 8](https://reader036.vdocument.in/reader036/viewer/2022062802/56649ed05503460f94bddc49/html5/thumbnails/6.jpg)
MLS 04/21/23 6
Thinking about Parallelism
Is it more or less fundamental than sequentiality?
May be a silly question» Dependences among algorithm steps form a partial
order» I don’t care if you call it
– a restriction of the empty order– or a relaxation of some total order
Both are ways of thinking about the ordering of algorithmic steps (state transformers)
![Page 7: MLS 10/18/2015 1 Don’t Start with Dekker’s Algorithm: Top-Down Introduction of Concurrency Michael L. Scott Multicore Programming Education Workshop 8](https://reader036.vdocument.in/reader036/viewer/2022062802/56649ed05503460f94bddc49/html5/thumbnails/7.jpg)
MLS 04/21/23 7
Concurrency as Control Flow
My languages text/course talks about» sequencing» selection» iteration» procedural abstraction» recursion» concurrency» exception handling
and speculation» nondeterminacy
![Page 8: MLS 10/18/2015 1 Don’t Start with Dekker’s Algorithm: Top-Down Introduction of Concurrency Michael L. Scott Multicore Programming Education Workshop 8](https://reader036.vdocument.in/reader036/viewer/2022062802/56649ed05503460f94bddc49/html5/thumbnails/8.jpg)
MLS 04/21/23 8
Top-Down Concurrency
parallel libraries
deterministic parallelism
event-driven thread-based
message-based
low-level races
explicitly synchronized
![Page 9: MLS 10/18/2015 1 Don’t Start with Dekker’s Algorithm: Top-Down Introduction of Concurrency Michael L. Scott Multicore Programming Education Workshop 8](https://reader036.vdocument.in/reader036/viewer/2022062802/56649ed05503460f94bddc49/html5/thumbnails/9.jpg)
MLS 04/21/23 9
Use» par-do or spawn/sync w/compiler-
enforced dynamic separation» speculation in sequential programs» futures in pure functional languages» safe futures in impure languages
And maybe» par-do, spawn/sync, or unsafe
futures, w/out enforced separation» HPF for-all
Consider» locality» granularity» load balance» design patterns
Straightforward
![Page 10: MLS 10/18/2015 1 Don’t Start with Dekker’s Algorithm: Top-Down Introduction of Concurrency Michael L. Scott Multicore Programming Education Workshop 8](https://reader036.vdocument.in/reader036/viewer/2022062802/56649ed05503460f94bddc49/html5/thumbnails/10.jpg)
MLS 04/21/23 10
Use» atomic blocks» PO-iterators» loop post-wait» map-reduce» condition sync» locks, monitors, CCRs» send/receive/rendezvous
Consider» progress» happens-before» data race freedom» 2-phase commit» consensus, self-
stabilization, Byzantine agreement, etc.
![Page 11: MLS 10/18/2015 1 Don’t Start with Dekker’s Algorithm: Top-Down Introduction of Concurrency Michael L. Scott Multicore Programming Education Workshop 8](https://reader036.vdocument.in/reader036/viewer/2022062802/56649ed05503460f94bddc49/html5/thumbnails/11.jpg)
MLS 04/21/23 11
Build» implementation of threads,
locks, monitors, transactions, etc.
» nonblocking data structures
» non-DRF algorithms
Consider» memory
models/consistency
» linearizability, serializability
» consensus hierarchy
![Page 12: MLS 10/18/2015 1 Don’t Start with Dekker’s Algorithm: Top-Down Introduction of Concurrency Michael L. Scott Multicore Programming Education Workshop 8](https://reader036.vdocument.in/reader036/viewer/2022062802/56649ed05503460f94bddc49/html5/thumbnails/12.jpg)
MLS 04/21/23 12
Where in the Curriculum?
languages, SW engg., sci. comp.
graphics, HCI, web computing
computer literacydata structures
networks, dist. comp.
OS, arch., par. comp., DBMS
![Page 13: MLS 10/18/2015 1 Don’t Start with Dekker’s Algorithm: Top-Down Introduction of Concurrency Michael L. Scott Multicore Programming Education Workshop 8](https://reader036.vdocument.in/reader036/viewer/2022062802/56649ed05503460f94bddc49/html5/thumbnails/13.jpg)
MLS 04/21/23 13
Motivation and Rewards
Need clear payoff, at each step of the way,to motivate further investment/refinement» speedup (even if modest, e.g., on 2-core machine)» clarity (for event-driven and naturally multithreaded
code) Will benefit greatly from access
to parallel machines» Simulators are lousy motivation» Niagara boxes are cheap
![Page 14: MLS 10/18/2015 1 Don’t Start with Dekker’s Algorithm: Top-Down Introduction of Concurrency Michael L. Scott Multicore Programming Education Workshop 8](https://reader036.vdocument.in/reader036/viewer/2022062802/56649ed05503460f94bddc49/html5/thumbnails/14.jpg)
MLS 04/21/23 14
What Language Do We Use?
Lamport: This is the wrong question.» “Imagine an art historian answering ‘how would you
describe impressionist painting?’ by saying ‘in French’.”
MLS: This is thewrong analogy.» Imagine an art
teacher answering“how would youintroduce pointillism?”by saying “in oils”.
Notation matters!
![Page 15: MLS 10/18/2015 1 Don’t Start with Dekker’s Algorithm: Top-Down Introduction of Concurrency Michael L. Scott Multicore Programming Education Workshop 8](https://reader036.vdocument.in/reader036/viewer/2022062802/56649ed05503460f94bddc49/html5/thumbnails/15.jpg)
MLS 04/21/23 15
Algol 68
[]REAL M = (0.0, 0.0);...BEGIN M[0] := f(M[0]), # note comma M[1] := g(M[1])END
![Page 16: MLS 10/18/2015 1 Don’t Start with Dekker’s Algorithm: Top-Down Introduction of Concurrency Michael L. Scott Multicore Programming Education Workshop 8](https://reader036.vdocument.in/reader036/viewer/2022062802/56649ed05503460f94bddc49/html5/thumbnails/16.jpg)
MLS 04/21/23 16
Java 5
static class A implements Runnable { double M[]; A(double m[]) {M = m;} public void run () { M[0] = f(M[0]); }}...double M[] = new double[2];ExecutorService pool = Executors.newFixedThreadPool(2);pool.execute(new A(M));pool.execute(new B(M));pool.shutdown();try { boolean finished = pool.awaitTermination(10, TimeUnit.SECONDS);} catch (InterruptedException e) { }
static class B implements Runnable { double M[]; B(double m[]) {M = m;} public void run () { M[1] = g(M[1]); }}
![Page 17: MLS 10/18/2015 1 Don’t Start with Dekker’s Algorithm: Top-Down Introduction of Concurrency Michael L. Scott Multicore Programming Education Workshop 8](https://reader036.vdocument.in/reader036/viewer/2022062802/56649ed05503460f94bddc49/html5/thumbnails/17.jpg)
MLS 04/21/23 17
C# 3.0
double[] M = new double[2];Parallel.Do( delegate { M[0] = f(M[0]); }, delegate { M[1] = g(M[1]); });
Where are the other options?» production quality (with good IDE)» widely used (for practical-minded students)
![Page 18: MLS 10/18/2015 1 Don’t Start with Dekker’s Algorithm: Top-Down Introduction of Concurrency Michael L. Scott Multicore Programming Education Workshop 8](https://reader036.vdocument.in/reader036/viewer/2022062802/56649ed05503460f94bddc49/html5/thumbnails/18.jpg)
MLS 04/21/23 18
Summary Recap
Integrate parallelism & concurrency into the whole curriculum
Introduce it gradually where it naturally fits
Provide clear motivation and payoff at each step
Assign projects on real machines
In real programming languages
![Page 19: MLS 10/18/2015 1 Don’t Start with Dekker’s Algorithm: Top-Down Introduction of Concurrency Michael L. Scott Multicore Programming Education Workshop 8](https://reader036.vdocument.in/reader036/viewer/2022062802/56649ed05503460f94bddc49/html5/thumbnails/19.jpg)
www.cs.rochester.edu/research/synchronization/