1 / 19

Programming Paradigms for Concurrency

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

allie
Download Presentation

Programming Paradigms for Concurrency

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming Paradigms for Concurrency PavolCernyVasu Singh Thomas Wies Part III – Message Passing Concurrency

  2. 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

  3. 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

  4. Actors object-oriented approach to concurrency “actor = object + logical thread” [Hewitt, Bishop, Steiger 1973, Agha 1986]

  5. 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

  6. Example: Ping-Pong Actors Pong Ping PingMsg pong

  7. Example: Ping-Pong Actors Pong Ping PongMsg pong PingMsg sender

  8. Example: Concurrent Merge Sort Sorter Sorter 3 2 5 1 Sorter

  9. Example: Concurrent Merge Sort Sorter Sorter 1 3 2 5 Sorter

  10. Example: Concurrent Merge Sort Sorter Sorter 1 Sorter 2 Sorter Sorter Sorter 5 Sorter 3

  11. Example: Concurrent Merge Sort Sorter 1 Sorter Sorter 2 Sorter Sorter 5 Sorter Sorter 3

  12. Example: Concurrent Merge Sort Sorter Sorter 1 Sorter 2 Sorter Sorter Sorter 5 Sorter 3

  13. Example: Concurrent Merge Sort Sorter 2 Sorter 1 3 Sorter 5

  14. Example: Concurrent Merge Sort Sorter Sorter 2 1 5 3 Sorter

  15. 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

  16. 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)))

  17. 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

  18. 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.

  19. 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!

More Related