ACCU 2012: Go, D, C++ and The Multicore Revolution
-
Upload
russel-winder -
Category
Technology
-
view
2.175 -
download
3
description
Transcript of ACCU 2012: Go, D, C++ and The Multicore Revolution
Copyright © 2011–2012 Russel Winder 1
Go, D, C++ and theMulticore Revolution
Russel Winder
email: [email protected]: [email protected]
twitter: russel_winder
Copyright © 2011–2012 Russel Winder 2
Aims, Goals and Objects
● Show that shared memory multi-threading should return to being an operating systems development technique and not continue to be pushed as an applications programming technique.
● Show, possibly, that the C++11 standard may, perhaps, have saved C++ from the dustbin of obscurity.
Copyright © 2011–2012 Russel Winder 3
Structure
A beginning.
A middle.
An end.
Copyright © 2011–2012 Russel Winder 4
Protocol
● Questions or short comments during the session are entirely in order.
● Let me know you have an interjection by raising your hand, and when I come to an appropriate pause, I'll pass you the token.
Questions, answers, comments, etc. appearingto get too long as interjections may get stackedto be unstacked at a break.
Copyright © 2011–2012 Russel Winder 5
Interstitial Advertisement
Copyright © 2011–2012 Russel Winder 6
A Beginning
Copyright © 2011–2012 Russel Winder 7
It is no longer contentious thatThe Multicore Revolution
is well underway.
Copyright © 2011–2012 Russel Winder 8
Quad core laptops and phones.
Eight and twelve core workstations.
Servers with “zillions” of cores.
Copyright © 2011–2012 Russel Winder 9
Software technologyis now lagging
hardware technologyby decades.
Copyright © 2011–2012 Russel Winder 10
Operating systems manage coreswith kernel threads.
Operating systems are fundamentally shared memory multi-threaded systems.
Operating systems rightly use all the lock, semaphore, monitor, etc. technologies.
Copyright © 2011–2012 Russel Winder 11
Operating systems really rather needto be native code systems.
Copyright © 2011–2012 Russel Winder 12
Constructive dichotomies…
Copyright © 2011–2012 Russel Winder 13
Native code languages.
vs.
Virtual machine based languages.
Copyright © 2011–2012 Russel Winder 14
Statically typed languages.
vs.
Dynamically typed languages.
Copyright © 2011–2012 Russel Winder 15
Compiled languages.
vs.
Scripting languages languages.
Copyright © 2011–2012 Russel Winder 16
Imperative languages.
vs.
Declarative languages.
Copyright © 2011–2012 Russel Winder 17
Sequential.
vs.
Parallel.
Copyright © 2011–2012 Russel Winder 18
Computationally intensive.
vs.
I/O intensive.
Copyright © 2011–2012 Russel Winder 19
Batch flow.
vs.
Event driven.
Copyright © 2011–2012 Russel Winder 20
Monolithic systems.
vs.
Cooperating subsystems.
Copyright © 2011–2012 Russel Winder 21
Computationally intensive systems orsubsystems definitely have to be parallel.
Other systems likely use concurrencybut not parallelism.
Copyright © 2011–2012 Russel Winder 22
Concurrency is a design tool.
Parallelism is a tool to improvecomputational performance.
Copyright © 2011–2012 Russel Winder 23
Static vs. Dynamic
● Fortran● C● C++● D● Go● Rust● Java● Scala● Ceylon● Kotlin
● Python, Jython
● Lisp, Clojure
● Ruby, JRuby
● Groovy
● JavaScript
● Dart
COBOL
Copyright © 2011–2012 Russel Winder 24
A Middle
Copyright © 2011–2012 Russel Winder 25
It's all about controllingconcurrency with tools that programmers find usable.
Copyright © 2011–2012 Russel Winder 26
Shared memory multi-threading is an operating system technique.
Copyright © 2011–2012 Russel Winder 27
Applications and tools programmersneed computational models with
integrated synchronization.
Copyright © 2011–2012 Russel Winder 28
ActorsIndependent processes communicating via asynchronous exchange of messages
CSPSequential processes connected by channels using synchronous message exchange (rendezvous).
DataflowOperators connected by channels with activity triggered by arrival of data on the channels.
Copyright © 2011–2012 Russel Winder 29
ActorsIndependent processes communicating via asynchronous exchange of messages
Copyright © 2011–2012 Russel Winder 30
DataflowOperators connected by channels with activity triggered by arrival of data on the channels.
Copyright © 2011–2012 Russel Winder 31
CSPSequential processes connected by channels using synchronous message exchange (rendezvous).
Copyright © 2011–2012 Russel Winder 32
Need examples.
Copyright © 2011–2012 Russel Winder 33
Copyright © 2011–2012 Russel Winder 34
What is the Value of ?
● Easy, it's known exactly, it's (obviously).
It's simples
Александр Орлов 2009
Copyright © 2011–2012 Russel Winder 35
Approximating
● What is it's value represented as a floating point number?● We can only obtain an approximation.● A plethora of possible algorithms to choose from, a
popular one is to employ the following integral equation.
4=∫0
1 1
1x2dx
Copyright © 2011–2012 Russel Winder 36
One Possible Algorithm
● Use quadrature to estimate the value of the integral – which is the area under the curve.
=4n∑i=1
n 1
1i−0.5n
2
With n = 3 not much to do, but potentially lots of error. Use n = 107 or n = 109?
Embarrassingly parallel.
Copyright © 2011–2012 Russel Winder 37
Scatter – Gather
map reduce
Copyright © 2011–2012 Russel Winder 38
Code!
Copyright © 2011–2012 Russel Winder 39
Need another example.
Copyright © 2011–2012 Russel Winder 40
The Sleeping Barber Problem
Copyright © 2011–2012 Russel Winder 41
The Sleeping Barber Problem
● The barber's shop has a single cutting chair and a row of waiting seats.
● The barber sleeps in the cutting chair unless trimming a customer.
● Customers arrive at the shop at intervals.
● If the barber is asleep, the customer wakes the barber takes the cutting chair and gets a trim.
● If the barber is cutting, a new customer checks to see if there is a free waiting seat.
● If there is join the queue to be trimmed.
● If there isn't leave disgruntled.
Problem originally dueto Edsgar Dijkstra.
Copyright © 2011–2012 Russel Winder 42
A new customer enters the shop,check to see if they can go straightto the cutting chair, if not can theytake a waiting chair, if not leave.
The waiting chairs
The cutting chair.
The barber's shop.
Copyright © 2011–2012 Russel Winder 43
Wikipedia article presents the classic operating systems approach using locks and semaphores.
http://en.wikipedia.org/wiki/Sleeping_barber_problem
Copyright © 2011–2012 Russel Winder 44
More code!
Copyright © 2011–2012 Russel Winder 45
Note to Self:
Did you, in fact, show all the examples in:
● C● D● Go● C++● Python
Copyright © 2011–2012 Russel Winder 46
An End
Copyright © 2011–2012 Russel Winder 47
Native code language are just asmuch scripting languages asvirtual machine languages
and interpreted ones.
Copyright © 2011–2012 Russel Winder 48
Virtual machine languages arejust as fast as native code
languages when using JITs.
Copyright © 2011–2012 Russel Winder 49
Multicore and multiprocessorare now the norm,not the exception.
Copyright © 2011–2012 Russel Winder 50
Parallelism only mattersif computational
performance matters.
Copyright © 2011–2012 Russel Winder 51
Unstructured synchronizationof concurrent systems
is not a feasible approach.
Copyright © 2011–2012 Russel Winder 52
Actors, CSP and Datafloware the future of
applications structure.
Copyright © 2011–2012 Russel Winder 53
Passing messages betweenprocesses is the way forward.
Copyright © 2011–2012 Russel Winder 54
Shared memory concurrencyis a dead end for applications.
Copyright © 2011–2012 Russel Winder 55
Surreptitious Advertisement
Copyright © 2011–2012 Russel Winder 56
The End
Copyright © 2011–2012 Russel Winder 57
Go, D, C++ and theMulticore Revolution
Russel Winder
email: [email protected]: [email protected]
twitter: russel_winder