190 likes | 411 Views
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
E N D
Programming Paradigms for Concurrency PavolCernyVasu Singh Thomas Wies Part III – Message Passing Concurrency
The Downsides of Classical Shared Memory Concurrency • shared memory typically implies physicallyshared memory • locks: the “goto statements” of concurrency • OS threads are resource-hungry and context-switching is expensive • no natural adaptation to distributed settings • reasoning about programs is (even more) difficult • number of threads = number of available cores • ≠ number of logical tasks
Overview of Part III • Message Passing Programming Paradigms • actors (Scala) • first-class synchronous events (Concurrent ML) • MP Programming Techniques • client/server programming • process networks • Formal Semantics of MP Programs • process calculi • 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 B A A
Example: Ping-Pong Actors Pong Ping PingMsg pong
Example: Ping-Pong Actors Pong Ping PongMsg pong PingMsg sender
Example: Concurrent Merge Sort Sorter Sorter 3 2 5 1 Sorter
Example: Concurrent Merge Sort Sorter Sorter 1 3 2 5 Sorter
Example: Concurrent Merge Sort Sorter Sorter 1 Sorter 2 Sorter Sorter Sorter 5 Sorter 3
Example: Concurrent Merge Sort Sorter 1 Sorter Sorter 2 Sorter Sorter 5 Sorter Sorter 3
Example: Concurrent Merge Sort Sorter Sorter 1 Sorter 2 Sorter Sorter Sorter 5 Sorter 3
Example: Concurrent Merge Sort Sorter 2 Sorter 1 3 Sorter 5
Example: Concurrent Merge Sort Sorter Sorter 2 1 5 3 Sorter
CCS - A Process Calculus terminated process process identifier internal action input action output action parallel composition choice channel restriction P,Q ::= 0 | A(a1,…,an) | ¿.P | a?P | a!P | P “|” Q | P + Q | (º a) P
CCS - A Process Calculus Processes are defined by systems of recursive equations Ping(ping, pong) = Msg(ping) | (pong ? Ping(ping, pong)) Pong(ping, pong) = ping ? (Msg(pong) | Pong (ping, pong)) Msg(a) = a ! 0 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)))
Project Proposals • Performance/Conciseness Evaluation of Concurrent Programming Paradigms Compare 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 • 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 • 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!