Top Banner
Alternate Concurrency Models Abid Hossain Khan
24
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Alternate concurrency models

Alternate Concurrency Models

Abid Hossain Khan

Page 2: Alternate concurrency models

Agenda

Common Problems of multi-threading

Concurrency Models

Actor Model

Software Transactional Memory (STM)

Page 3: Alternate concurrency models

Common Problems of multi-threading: Thread states

Page 4: Alternate concurrency models

Common Problems of multi-threading

• Atomicity

• Visibility

• Reordering

• Race Condition

• Livelock

• Starvation

• Deadlock

Page 5: Alternate concurrency models

Concurrency Models

• Thread & Locks

• Actors

• Communicating Sequential Process

• Disrupter

Page 6: Alternate concurrency models

Thread & Locks

Page 7: Alternate concurrency models

Actor Model

Page 8: Alternate concurrency models

Communicating Sequential Process

• Special Actor system with mailbox size 0

Page 9: Alternate concurrency models

Disrupter

Page 10: Alternate concurrency models

Actor Model

• What is Actor

• Actor Fundamentals

• Actor Semantics

• Actor Anatomy

• Actor on JVM

• Actor based Applications

Page 11: Alternate concurrency models

What is Actor

Actor model is a universal primitive of concurrent computation in computer science.

Behaviors of Actor It can make local decision. It can create more actors Send more messages Determine how to respond to the next message received

It is based on responsive manifesto

Page 12: Alternate concurrency models

Actor Fundamentals

Autonomous

No shared state

Asynchronous message passing

Page 13: Alternate concurrency models

Actor Semantics

Encapsulation

Fairness

Location Transparency

Mobility

Page 14: Alternate concurrency models

Actor Anatomy

Page 15: Alternate concurrency models

Actor on JVM

Java

Scala

Groovy

Fantom

ActorFoundry

Closure

Kilim

Page 16: Alternate concurrency models

Example Applications

Martian Rover (1990)

Facebook Chat (implemented using Erlang)

Twitter message queuing

Play Framework (Typesafe stack)

LiftWeb Framework (Scala for web applications)

Vendatta game engine (Erlang)

Image processing in MS Visual Studio 2010

Page 17: Alternate concurrency models

Software Transactional Memory

• What is STM

• The Bacis

• Pros & Cons

• Implementations

Page 18: Alternate concurrency models

What is STM

Analogous to database transaction

Concurrency is controlled in shared memory location

Here transaction occurs when code executes series of reads & writes to shared memory

Transaction is atomic i.e. all reads & writes happens as a single logical operation or none.

Intermediate states are not visible to other transactions

Page 19: Alternate concurrency models

Software Transactional Memory: The Basics

1. Reads/Writes happens to shared memory without regards of what other threads are doing

2. Records every read and write in a log file

3. After completion a validation is performed.

3.1 If validation is successful, changes are made permanent i.e. commit

3.2 Transaction is rolled back. When a transaction is rolled back, transaction re-executes its steps until it succeeds

Page 20: Alternate concurrency models

Software Transactional Memory: Pros & Cons

Pros

It is simpler as transaction in isolation can be viewed as single-threaded computation

Programmer does not need to worry about deadlock or livelock

Cons

Additional overhead in maintaining log and committing transactions

Page 21: Alternate concurrency models

STM : Implementations

Java

DeuceSTM

ScalaSTM

Multiverse

Page 22: Alternate concurrency models

References

http://www.somanyword.com/2014/03/common-problems-of-concurrency-multi-threading-in-java/

http://java-is-the-new-c.blogspot.in/2014/01/comparision-of-different-concurrency.html

http://sbtourist.blogspot.in/2009/02/actor-concurrency-model-in-nutshell.html

Page 23: Alternate concurrency models
Page 24: Alternate concurrency models

Thank You