alternate concurrency models

24
Alternate Concurrency Models Abid Hossain Khan

Upload: abid-khan

Post on 08-Aug-2015

47 views

Category:

Software


1 download

TRANSCRIPT

Alternate Concurrency Models

Abid Hossain Khan

Agenda

Common Problems of multi-threading

Concurrency Models

Actor Model

Software Transactional Memory (STM)

Common Problems of multi-threading: Thread states

Common Problems of multi-threading

• Atomicity

• Visibility

• Reordering

• Race Condition

• Livelock

• Starvation

• Deadlock

Concurrency Models

• Thread & Locks

• Actors

• Communicating Sequential Process

• Disrupter

Thread & Locks

Actor Model

Communicating Sequential Process

• Special Actor system with mailbox size 0

Disrupter

Actor Model

• What is Actor

• Actor Fundamentals

• Actor Semantics

• Actor Anatomy

• Actor on JVM

• Actor based Applications

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

Actor Fundamentals

Autonomous

No shared state

Asynchronous message passing

Actor Semantics

Encapsulation

Fairness

Location Transparency

Mobility

Actor Anatomy

Actor on JVM

Java

Scala

Groovy

Fantom

ActorFoundry

Closure

Kilim

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

Software Transactional Memory

• What is STM

• The Bacis

• Pros & Cons

• Implementations

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

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

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

STM : Implementations

Java

DeuceSTM

ScalaSTM

Multiverse

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

Thank You