alternate concurrency models
TRANSCRIPT
Agenda
Common Problems of multi-threading
Concurrency Models
Actor Model
Software Transactional Memory (STM)
Common Problems of multi-threading
• Atomicity
• Visibility
• Reordering
• Race Condition
• Livelock
• Starvation
• Deadlock
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
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
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
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