History of Concurrency
OSBridge | 21 Jun 2014
What is concurrency?
...and why is it important?
Concurrency is...
...the composition of independently executing tasks.
Dependent Tasks
import redis��client = redis.Redis('localhost')�counter_key = client.get('foreign_key1')�client.incr(counter_key)
Independent Tasks
import redis��client = redis.Redis('localhost')�client.incr('counter1')�client.incr('counter2')
Concurrent Tasks
package main��import "net/http"��func main() {� go http.Get("http://google.com/?q=independent")� go http.Get("http://google.com/?q=tasks")�}
Parallelism is...
...the simultaneous execution of multiple tasks.
Concurrency vs Parallelism
Why does concurrency matter?
You cannot execute code in parallel if it is not written to be concurrent.
Concurrency:
Easy for computers; hard for humans.
Why should you learn about it?
Hardware
not included
(in this talk)
Not a distributed systems talk
Xxxxx
The History of Concurrency
...everything was invented in the 60s and 70s...
All the wars have been won
1979 - The Duality Argument asserts threaded and evented systems are logically equivalent.
Even the performance is equivalent.
When were threads invented?
Depends on what we mean by “thread”
What are threads?
(Worst diagram ever.)
3 concepts to know before understanding threads...
#1 - Primitives vs. Models
Models
Design Patterns
Primitives
Primitives
Primitives
Primitives
#1 Primitives, Patterns, and Models
Patterns
Models
#1 Primitives, Patterns, and Models
Models evolve into Primitives
Models
Design Patterns
Primitives
Primitives
Primitives
#1 Primitives, Patterns, and Models
Evolution Example: Monitors
mutex + condition + object = monitor
#1 Primitives, Patterns, and Models
Modern examples of primitive evolution:
Erlang did it all in the 80s but we’ll come back to it...
#2 Task Scheduling
#1 Primitives, Patterns, and Models
If there are multiple tasks, who decides when each one executes and how?
The Two Scheduling Modes
Preemptive
Modern OS Threads
Modern OS Processes
Goroutines
Erlang Processes
UNIX Signals
Cooperative
Callbacks
Coroutines
Continuations
Fibers
Greenthreads
Cooperative Concurrency
Preemptive Concurrency
#2 Task Scheduling
Modern language examples:
#3 Methods of Interaction
#1 Primitives, Patterns, and Models
#2 Task Scheduling
If tasks are independent, how do they communicate?
Shared Memory
Message Passing
Synchronization
Coordinate via:
Communication
Communicate via:
Message Passing Models: Actors
#3 Methods of Interaction
Erlang (1986)
#3 Methods of Interaction
Actor model in core language & runtime
Erlang’s Philosophy
#3 Methods of Interaction
“The world is concurrent
Things in the world don’t share data
Things communicate with messages
Things fail
Model this in a language” — Joe Armstrong
Message Passing Models: CSP
#3 Methods of Interaction
Communicating Sequential Processes
#3 Methods of Interaction
Threads share memory (and therefore require synchronization which is tricky to get right).
"Threads, as a model of computation, are wildly non-deterministic, and the job of the programmer becomes one of pruning that nondeterminism."
#3 Methods of Interaction
— The Problem with Threads, Edward A. Lee, UC Berkeley, 2006
Threading is not a model
#3 Methods of Interaction
Threading is an important primitive
Build concurrency models on top of threads
Modern Frameworks: Akka (2009)
3 Concurrency Concepts
Concurrency Today
C++0x, Java, Python, and Ruby
C#
D
Javascript and Dart
Go
Rust
https://air.mozilla.org/guaranteeing-memory-safety-in-rust/
Julia and Erlang
Haskell and Clojure
“New” Concurrency Primitive: STM
Software Transactional Memory
The Future of Concurrency
Thanks!
Michael Schurter
michael.schurter@gmail.com
@schmichael
schmichael on Freenode
License
The text and slides are CC0 1.0 Universal (CC0 1.0) licensed.
The images are copyright their respective owners.