programming paradigms for concurrency
DESCRIPTION
Programming Paradigms for Concurrency. Pavol Cerny Vasu Singh Thomas Wies Part III – Message Passing Concurrency. The Downsides of Classical Shared Memory Concurrency. shared memory typically implies physically shared memory l ocks: the “ goto statements ” of concurrency - PowerPoint PPT PresentationTRANSCRIPT
Programming Paradigms for Concurrency
Pavol Cerny Vasu Singh Thomas Wies
Part III – Message Passing Concurrency
The Downsides of Classical Shared Memory Concurrency
• shared memory typically implies physically shared memory
• locks: the “goto statements” of concurrency
• OS threads are resource-hungry and context-switching is expensivenumber of threads = number of available cores
≠ number of logical tasks
no natural adaptation to distributed settings
reasoning about programs is (even more) difficult
Overview of Part III
1. Message Passing Programming Paradigms- actors (Scala)- first-class synchronous events (Concurrent ML)
2. MP Programming Techniques– client/server programming– process networks
3. Formal Semantics of MP Programs– process calculi
4. Formal Reasoning about MP Programs- behavioral equivalences- verifying safety and liveness properties
Actors
object-oriented approach to concurrency
“actor = object + logical thread”
[Hewitt, Bishop, Steiger 1973, Agha 1986]
Actors• actors perform local computations and communicate via MP• communication is
– asynchronous– buffered (in practice FIFO)– over unique-receiver channels (mailboxes)
• computation is – even-driven: react to incoming messages– dynamically create other actors– send messages to other actors– dynamically change behavior
• languages supporting actor-based concurrency– Erlang– Salsa– Scala– many implementations in form of libraries
A
A
B
Example: Ping-Pong Actors
Ping Pongpong
PingMsg
Example: Ping-Pong Actors
Ping Pongpong
PingMsg
sender
PongMsg
Example: Concurrent Merge Sort
Sorter1523
Sorter
Sorter
Sorter
Sorter
Example: Concurrent Merge Sort
Sorter1
5
23
Sorter
Sorter
Sorter
Sorter
Sorter
Sorter
Example: Concurrent Merge Sort
Sorter
1
5
2
3
Sorter
Sorter
Sorter
Sorter
Sorter
Sorter
Example: Concurrent Merge Sort
Sorter
1
5
2
3
Sorter
Sorter
Sorter
Sorter
Sorter
Sorter
Example: Concurrent Merge Sort
Sorter
1
5
2
3
Sorter
Sorter
Example: Concurrent Merge Sort
Sorter
5
2
1
3
Sorter
Sorter
Example: Concurrent Merge Sort
Sorter3
2
51
CCS - A Process Calculus
P,Q ::= 0 | A(a1,…,an)
| ¿.P | a?P | a!P | P “|” Q | P + Q | (º a) P
terminated processprocess identifierinternal actioninput actionoutput actionparallel composition choicechannel restriction
CCS - A Process Calculus
Processes are defined by systems of recursive equations
Ping(ping, pong) = Msg(ping) | (pong ? Ping(ping, pong))
Formal semantics given in terms of labeled transition systems) enables formal reasoning about MP programs
Diverge() = ¿.Diverge()
Diverge() ´ (º ping, pong) ((Ping(ping, pong) | Pong (ping, pong)))
Pong(ping, pong) = ping ? (Msg(pong) | Pong (ping, pong))
Msg(a) = a ! 0
Project Proposals
1. Performance/Conciseness Evaluation of Concurrent Programming ParadigmsCompare idiomatic implementations of the same algorithm in Scala using different programming paradigms:– a sequential implementation– a concurrent implementation based on actors– a concurrent implementation based on shared
memory
Project Proposals
2. First-Class Synchronous Events in Scala– Take inspiration from the Scala Actor Library and
the CML library– Implement a Scala library supporting first-class
synchronous events.
Project Proposals
3. Verification of Scala Actor Programs– Implement a non-trivial Scala Actor program or
take an existing one – Manually compute finite-state abstractions of all
actors– Verify properties of the abstracted program using a
formal verification tool for MP programs
Please drop by or send me an email to discuss concrete projects!