Contenu connexe Similaire à It's all about processes communicating - Russel Winder (20) It's all about processes communicating - Russel Winder1. It's All About
Processes Communicating
Russel Winder
email: russel@winder.org.uk
xmpp: russel@winder.org.uk
twitter: russel_winder
Copyright © 2011–2012 Russel Winder 1
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 that…
Copyright © 2011–2012 Russel Winder 2
3. …people should tremble in fear
at the prospect of using
Shared-memory
multithreading.
Copyright © 2011–2012 Russel Winder 3
4. Structure
A beginning.
A middle.
An end.
Copyright © 2011–2012 Russel Winder 4
5. 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. appearing
to get too long as interjections may get stacked
to be unstacked at a break.
Copyright © 2011–2012 Russel Winder 5
8. It is no longer contentious that
The Multicore Revolution
is well underway.
Copyright © 2011–2012 Russel Winder 8
9. Quad core laptops and phones.
Eight and twelve core workstations.
Servers with “zillions” of cores.
Copyright © 2011–2012 Russel Winder 9
12. Operating systems manage cores
with 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 12
13. Computationally intensive systems or
subsystems definitely have to be parallel.
Other systems likely use concurrency
but not parallelism.
Copyright © 2011–2012 Russel Winder 13
14. Concurrency
Execution as co-routines:
Sequences of code give up the execution
to pass it to another coroutine.
Copyright © 2011–2012 Russel Winder 14
15. More Concurrency
Concurrency is a technique founded in a
uniprocessor view of the world.
Time-division multiplexing.
Copyright © 2011–2012 Russel Winder 15
16. Parallelism
Having multiple executions active
at the same time.
Copyright © 2011–2012 Russel Winder 16
17. Concurrency is a tool for structuring execution where a
single processor is used by multiple computations.
Parallelism is about making a computation complete
faster than using a single processor.
Copyright © 2011–2012 Russel Winder 17
26. Thanks to Paul King…
Who uses synchronized?
Copyright © 2011–2012 Russel Winder 26
27. Thanks to Paul King…
You did it wrong.
Copyright © 2011–2012 Russel Winder 27
28. Small addition by me…
Who uses lock objects?
Copyright © 2011–2012 Russel Winder 28
29. Small addition by me…
You definitely did it wrong.
Copyright © 2011–2012 Russel Winder 29
31. The whole purpose of a lock is to
prevent parallelism.
Copyright © 2011–2012 Russel Winder 31
34. Locks are needed only if
there is mutable shared state.
Copyright © 2011–2012 Russel Winder 34
37. It's all easier if processes
are single threaded.
Copyright © 2011–2012 Russel Winder 37
41. It's all about controlling
concurrency and parallelism
with tools that programmers find usable.
Copyright © 2011–2012 Russel Winder 41
43. Applications and tools programmers
need computational models with
integrated synchronization.
Copyright © 2011–2012 Russel Winder 43
44. Dataflow
Operators connected by
Actors channels with activity
Independent processes triggered by arrival of
communicating via data on the channels.
asynchronous exchange
of messages
CSP
Sequential processes
connected by channels
using synchronous message
exchange (rendezvous).
Copyright © 2011–2012 Russel Winder 44
45. Actors
Independent processes
communicating via
asynchronous exchange
of messages
Copyright © 2011–2012 Russel Winder 45
46. Dataflow
Operators connected by
channels with activity
triggered by arrival of
data on the channels.
Copyright © 2011–2012 Russel Winder 46
47. CSP
Sequential processes
connected by channels
using synchronous message
exchange (rendezvous).
Copyright © 2011–2012 Russel Winder 47
50. What is the Value of ?
Easy, it's known exactly.
It's .
Obviously.
Copyright © 2011–2012 Russel Winder 50
51. It's simples
Александр Орлов 2009
Copyright © 2011–2012 Russel Winder 51
52. 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.
1 1
=∫0 dx
4 1x 2
Copyright © 2011–2012 Russel Winder 52
53. One Possible Algorithm
● Use quadrature to estimate the value of the integral
– which is the area under the curve.
4 n 1
= ∑i=1
n i−0.5 2
Embarrassingly 1
parallel. n
With n = 3 not much to do,
but potentially lots of error.
Use n = 107 or n = 109?
Copyright © 2011–2012 Russel Winder 53
54. Because addition is commutative and
associative, expression can be
decomposed into sums of partial sums.
Copyright © 2011–2012 Russel Winder 54
55. a+b+c+d+e+f
=
(a+b)+(c+d)+(e+f)
Copyright © 2011–2012 Russel Winder 55
58. If you want the code, clone the Git repository:
http://www.russel.org.uk/Git/Pi_Quadrature.git
Copyright © 2011–2012 Russel Winder 58
59. Or if you just want to browse:
http://www.russel.org.uk/gitweb
Copyright © 2011–2012 Russel Winder 59
62. The Sleeping Barber Problem
● The barber's shop has a ● If the barber is cutting, a new
single cutting chair and a row customer checks to see if
of waiting seats. there is a free waiting seat.
● The barber sleeps in the ● If there is join the queue
cutting chair unless trimming to be trimmed.
a customer. ● If there isn't leave
● Customers arrive at the shop disgruntled.
at intervals.
● If the barber is asleep, the
customer wakes the barber Problem originally due
takes the cutting chair and to Edsgar Dijkstra.
gets a trim.
Copyright © 2011–2012 Russel Winder 62
63. The cutting chair.
The waiting chairs
The barber's shop.
A new customer enters the shop,
check to see if they can go straight
to the cutting chair, if not can they
take a waiting chair, if not leave.
Copyright © 2011–2012 Russel Winder 63
64. 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 64
66. If you want the code, clone the Git repository:
http://www.russel.org.uk/Git/SleepingBarber.git
Copyright © 2011–2012 Russel Winder 66
67. Or if you just want to browse:
http://www.russel.org.uk/gitweb
Copyright © 2011–2012 Russel Winder 67
72. Actors, CSP and Dataflow
are the future of
applications structure.
Copyright © 2011–2012 Russel Winder 72
83. Don't be a squirrel.
Copyright © 2011–2012 Russel Winder 83
84. Do not use explicit locking algorithms.
Copyright © 2011–2012 Russel Winder 84
85. Use computational architectures that promote
parallelism and hence performance
improvement:
Actors
Dataflow
CSP
Data Parallelism
Copyright © 2011–2012 Russel Winder 85
86. Use
Go on, you know you want to…
Copyright © 2011–2012 Russel Winder 86
89. It's All About
Processes Communicating
Russel Winder
email: russel@winder.org.uk
xmpp: russel@winder.org.uk
twitter: russel_winder
Copyright © 2011–2012 Russel Winder 89