Robin Bate Boerop
Fredericton Developer User Group, 22 February 2012
The agenda includes the standard talk (search for “The Free Lunch Is Over”) to motivate learning to program with concurrency and parallelism.
Apologies if you have heard it before.
Estimated talk time: 1h15m.
This highly technical talk will explain the problems encountered by imperative programming languages (C/C++, Java), and will explain how functional programming languages and frameworks (Erlang, Node, Haskell) have created elegant solutions. The task of writing a high performance IRC server will serve as an example.
I am ditching the running example mentioned in the abstract.
Goal 1: To explain why understanding parallel and concurrent programming is more important than ever.
Goal 2: To point you to “ahead-of-the-curve” software development tools and techniques for including parallelism and concurrency in the software that you make.
(D&D joke appropriate for pre-WoW crowd.)
Concurrency: something to do with your problem.
Parallelism: seeking performance with repeated (or simply more) hardware.
Data parallelism:
Task parallelism:
Semi-implicit parallelism:
becomes
Advantages of Functional Programming for writing correct programs which include concurrency or parallelism.
module Main where
import Control.Monad
import Control.Concurrent
import Control.Concurrent.STM
atomRead = atomically . readTVar
dispVar x = atomRead x >>= print
appV fn x = atomically $ readTVar x >>= writeTVar x . fn
milliSleep = threadDelay . (*) 1000
main = do
shared <- atomically $ newTVar 0
before <- atomRead shared
putStrLn $ "Before: " ++ show before
forkIO $ 25 `timesDo`
(dispVar shared >> milliSleep 20)
forkIO $ 10 `timesDo`
(appV ((+) 2) shared >> milliSleep 50)
forkIO $ 20 `timesDo`
(appV pred shared >> milliSleep 25)
milliSleep 800
after <- atomRead shared
putStrLn $ "After: " ++ show after
where timesDo = replicateM_
Before: 0
0
1
0
1
0
1
1
0
1
0
1
1
0
1
0
1
1
0
1
0
1
1
0
1
0
After: 0