Escolar Documentos
Profissional Documentos
Cultura Documentos
Neil Brown
School of Computing
University of Kent
UK
15 March 2010
What is CHP?
Concurrency Parallelism
Concurrency Parallelism
id
Common Processes – The Identity Process
id
The Identity Process Pipeline
id id id id
The Identity Process Pipeline
id id id id
The Identity Process Pipeline
id id id id
4148
The Identity Process Pipeline
id id id id
4148
The Identity Process Pipeline
id id id id
4148
The Identity Process Pipeline
id id id id
4148
The Identity Process Pipeline
id id id id
2061 4148
The Identity Process Pipeline
id id id id
2061 4148
The Identity Process Pipeline
id id id id
197 3825 2061 4148
The Identity Process Pipeline
id id id id
197 3825 2061
The Identity Process Pipeline
id id id id
197 3825 2061
The Identity Process Pipeline
id id id id
197 3825 2061
The Identity Process (FIFO) Pipeline
id id id id
id id id id
id id id id
id id id id
fifo
id id id id
fifo
runCHP_ $ do
(resSend, resRecv) <- newChannelWR checkResponse
checkResponse printResults
checkResponse
Example – cURL
runCHP_ $ do
(resSend, resRecv) <- newChannelWR checkResponse
runParallel_ $
printResults resRecv :
map (claim resSend . writeValue
<=< liftIO . checkResponse) checkResponse printResults
details
checkResponse
Example – cURL
runCHP_ $ do
(resSend, resRecv) <- newChannelWR checkResponse
runParallel_ $
printResults resRecv :
map (claim resSend . writeValue
<=< liftIO . checkResponse) checkResponse printResults
details
printResults c
= replicateM_ (length details )
(readChannel c >>= liftIO . printResult )
Dynamically-Generated Work
checkResponse
checkResponse
Dynamically-Generated Work
getNextDetail :: IO Detail
checkResponse
Parallel Workers
manyIO :: Int -> (a -> IO b) -> Shared Chanin a -> Shared Chanout b ->
manyIO n worker input output
= runParallel_ . replicate n . forever $
claim input readChannel
>>= liftIO . worker
>>= claim output . writeValue
checkResponse
checkResponse
Putting It Together
checkResponse
checkResponse
pipelineConnectComplete’
(genIO getNextDetails)
(manyIO checkAuthResponse)
printResult
Pipeline With Feedback
checkResponse
checkResponse
Pipeline With Feedback
checkResponse
checkResponse
dynFilter
input output
filtInput
Altered Pipeline
checkResponse
checkResponse
Altered Pipeline
checkResponse
checkResponse
Pull Architectures/Laziness
checkResponse
checkResponse
Concurrent Termination
1
Concurrent Termination: Poison
Concurrent Termination: Poison
1
Concurrent Termination: Poison
2
Concurrent Termination: Poison
3
Concurrent Termination: Poison
4
Concurrent Termination: Poison
5
Poison
main :: IO ()
main = runTestTT testFreqWord >> return ()
Test Failure – Trace
### Failure:
testCHP Failure; trace: < _c4,
makeLower->words."the quick brown fox jumps over the lazy dog",
words->group.["the","quick","brown","fox",
"jumps","over","the","lazy","dog"],
group->maxByLength.[["the"],["quick"],["brown"],["fox"],
["jumps"],["over"],["the"],["lazy"],["dog"]],
maxByLength->head.["dog"],
_c5 >
Cases: 1 Tried: 1 Errors: 0 Failures: 1
Process Wiring
Wiring processes in a line is easy
Wiring processes in a line is easy
p ? q
Wiring processes in a line is easy
p =q r
r = p <=>q
Wiring processes in a line is easy
p
? q
?
Wiring processes in a line is easy
p q = r
r = p <=>q
The Connectable Type-Class
diningPhilosophers
= cycleConnect (concat (replicate 5 [ fork , philosopher]))
The Connectable class allows us to abstract common
topologies; the wrapped grid (torus)
f (x:xs) writeChannel
The Quest for Higher Ground
f (x:xs) writeChannel
Synchronisation Primitives:
Clocks
Barriers
Conjoined Events
Higher-Level Features:
Behaviours
Wiring monad
Formalisms:
CSP model generation
More trace types
Summary