Programming Paradigms for Concurrency

19
Programming Paradigms for Concurrency Pavol Cerny Vasu Singh Thomas Wies Part III – Message Passing 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 Presentation

Transcript of Programming Paradigms for Concurrency

Page 1: Programming Paradigms for Concurrency

Programming Paradigms for Concurrency

Pavol Cerny Vasu Singh Thomas Wies

Part III – Message Passing Concurrency

Page 2: Programming Paradigms for 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

Page 3: Programming Paradigms for Concurrency

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

Page 4: Programming Paradigms for Concurrency

Actors

object-oriented approach to concurrency

“actor = object + logical thread”

[Hewitt, Bishop, Steiger 1973, Agha 1986]

Page 5: Programming Paradigms for Concurrency

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

Page 6: Programming Paradigms for Concurrency

Example: Ping-Pong Actors

Ping Pongpong

PingMsg

Page 7: Programming Paradigms for Concurrency

Example: Ping-Pong Actors

Ping Pongpong

PingMsg

sender

PongMsg

Page 8: Programming Paradigms for Concurrency

Example: Concurrent Merge Sort

Sorter1523

Sorter

Sorter

Page 9: Programming Paradigms for Concurrency

Sorter

Sorter

Example: Concurrent Merge Sort

Sorter1

5

23

Page 10: Programming Paradigms for Concurrency

Sorter

Sorter

Sorter

Sorter

Sorter

Sorter

Example: Concurrent Merge Sort

Sorter

1

5

2

3

Page 11: Programming Paradigms for Concurrency

Sorter

Sorter

Sorter

Sorter

Sorter

Sorter

Example: Concurrent Merge Sort

Sorter

1

5

2

3

Page 12: Programming Paradigms for Concurrency

Sorter

Sorter

Sorter

Sorter

Sorter

Sorter

Example: Concurrent Merge Sort

Sorter

1

5

2

3

Page 13: Programming Paradigms for Concurrency

Sorter

Sorter

Example: Concurrent Merge Sort

Sorter

5

2

1

3

Page 14: Programming Paradigms for Concurrency

Sorter

Sorter

Example: Concurrent Merge Sort

Sorter3

2

51

Page 15: Programming Paradigms for Concurrency

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

Page 16: Programming Paradigms for Concurrency

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

Page 17: Programming Paradigms for Concurrency

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

Page 18: Programming Paradigms for Concurrency

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.

Page 19: Programming Paradigms for Concurrency

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!