This document discusses scaling up applications safely for concurrent programming. It begins by introducing concurrent and parallel computing concepts. The author then notes that obtaining performance benefits from newer CPUs now requires confronting the difficulty of concurrent programming. Examples are provided of potential concurrency issues like deadlocks. The document proposes an approach called "IA+ Threading" that avoids locks and scales well while not requiring completely rewiring one's brain. It discusses patterns like immutable state, message passing, and ensuring proper causality and event ordering for concurrency.
4. First things first
Concurrent computing
Form of computing in which
programs are designed as
collections of interacting
processes
no relation to the hardware it is
running on
4
5. First things first
Parallel computing
Form of computing in which
calculations are carried out
simultaneously
Implies that multiple processors are
available
5
6.
7. The Free Lunch is
over
Famous speech (2005) where Herb Sutter
stressed out that
CPU Frequency was no longer
progressing
Developers have to face concurrent
programming to expect to benefit from
newer CPU
but concurrent programming is hard
7
14. class C!
{!
static C() !
{!
// Let's run the initialization!
// on another thread!!
var thread = new Thread(Initialize);!
thread.Start();!
thread.Join();!
}!
static void Initialize() { }!
static void Main() { }!
}!
14
15. IT'S F*CKING HARD
You also need to master the
threading model of the CLR
Of course you need to master the
threading model of libraries
When was the last time you saw
and read a documented threading
model?
15
16. CAN'T GO BACK the free lunch is over
No complete solutions
RX, TPL: still requires lock
Clojure, ErLang: requires rewiring brain
GO: blocking primitives
Scala, F#: functional+ no thread safety
16
21. Immutable State
State is a mutable entity by
definition
But can be stored in a Value object
Altering the state means creating a
new version of the state
Immutability is good for sharing
22. Feedback
Run #1 was chaotic while run #2
was smoother
We just went from mutable to
immutable
23. Message passing
We also passed around the state of
the object as a message
Originaly used for commands but
works well with state as well
Since state is preserved, no need for
copies!
25. What about
causality?
How can we ensure events are
properly taken into accounts?
By the way, what do we mean by
'properly'?
26. Causality
1. Events can be totally ordered for
any given objects (source or dest)
2. There may not a be a total order
for all events and for all objects
27. Relativiy
Thanks to relativity, we know that
any two events can be SEEN in any
order
As long as they do not occur at the
same location
29. Pragmatic view
Events must be kept in their natural
local order
Generated events also must be kept
in the order they were generated
General ordering must remain
acceptable for a human