computational models

Download Computational models

Post on 09-Aug-2015




1 download

Embed Size (px)


  1. 1. Computational models in software engineering Dmitry Zagorulkin (
  2. 2. Concurrency in practice: - Distributed systems; - Fault tolerant systems; - Mobile systems(mobile phones network, vertices may connect and disconnect); - Parallel systems(running on one node)
  3. 3. Concurrency communication types: Shared memory usually required the application of some form of locking. (e.g. mutexes, semaphores, monitors). Java/C# Message passing concurrent components communicate by exchanging messages. Can be done in synchronous/asynchronous way. Mostly used in functional programming languages. Erlang/Scala(Akka)
  4. 4. Shared memory example
  5. 5. Shared memory example
  6. 6. Shared memory example Execution # Synchronized Not synchronized 1 Incr: 100000000Decr: 0 Decr: 67356100Incr: 67356100 2 Incr: 100000000Decr: 0 Decr: -88564700Incr: 1407800 3 Incr: 100000000Decr: 0 Decr: -86920200Incr: -1667800
  7. 7. Shared memory Advantages: easy to write such code deterministic behaviour Disadvantages: wrong waste of computer resources locking on resource hard to scale such code
  8. 8. Message passing example
  9. 9. Message passing example
  10. 10. Message passing Advantages: scalability out of the box possible to use in real time systems Disadvantages: hard to debug hard write code in such style
  11. 11. Models of computation (lambda) calculus by Church and Kleene (1941); (pi) calculus by Milner et. al. (1992); Actor model (1973) by Hewitt et. al; Join calculus (1996) by Fournet and Conthier; Mobile ambients (2000) by Cardelli and Gordon.
  12. 12. (lambda) calculus Used as a foundation for sequential computation; Heart of functional programming languages; Turing-complete; any computable function can be expressed and evaluated using the calculus; In the calculus, all functions may only have one variable;
  13. 13. (lambda) calculus Function: x.x2 ( the same f (x) = x2) Function application: (x.x2 2) 22 4. ( the same f (2) = 4) Currying and High order functions:h(x,y) = x + y, h: (Z x Z) -> Zf : Z -> ( Z -> Z) and gx : Z -> ZExample f(2) = g2, where g2(y) = 2 + y.f(2)(3) = g2(3) = 2 + 3 = 5in lambda calculus this function with currying by:x.y.x + y. (x.y.x+y 2) 3) (y.2+y 3) 2+3 5. Functions that operate on functions - rst class values, so function may be used as the inputs, or be returned as outputs from other functions.
  14. 14. (pi) calculus Pi calculus is a formal model for specication, analysis, and verication of systems composed of communicating concurrent processes. Concurrent computation is modeled in the Pi calculus as processes communicating over share channels. Calculus consist of processes {P,Q,R}, channel names {a,bc}, interaction (reading, writing) is denoted by prex . A simple interaction between two processes over a channel a can be modeled as follows in the calculus: a(x).P | b.Q
  15. 15. Actor model Asynchronous communication between nodes Every actor has its own identity ( used for communication) In response to message, an actor a may perform following: 1. send a message to a friend(acquaintance), an actor whose identity is known to the actor a 2. create a new actor a, with a given behaviour b 3. become ready to receive a new message with new behaviour b.
  16. 16. Actor model
  17. 17. Problems Reference cell problem (a cell contains mutable state. A simple cell can be created, updated, and queried by other concurrent computations) illustrates nondeterminism problem; Mutual exclusion (refers to the need of two or more concurrent computations to coordinate and avoid executing at the same some critical region of code) A useful abstraction for guaranteeing mutual exclusion is the notion of semaphores;
  18. 18. Problems Dining Philosophers A typical example of complexities of concurrent computation is the famous dining philosophers scenario. Consider n philosophiers, Ph1, , Phn -1, dining at a round table containing n chopsticks ch1, , chn-1 where each chopstick is shared by two consecutive philosophers. illustrates deadlock problem.
  19. 19. Dining philosophers algorithm 1. Pick left chopstick (if available) 2. Pick right chopstick (if available) 3. Eat 4. Release both chopsticks 5. Think 6. Go to 1
  20. 20. Actor language syntax
  21. 21. Actor model(reference cell problem)
  22. 22. Actor model(mutual exclusion)
  23. 23. Actor model(dining philosophers)
  24. 24. Alan Kay about OOP I thought of objects being like biological cells and/or individual computers on a network, only able to communicate with messages (so messaging came at the very beginning -- it took a while to see how to do messaging in a programming language efciently enough to be useful) Alan Kay.
  25. 25. Further Reading Programming distributed computing systems (A foundational approach) Carlos A. Varela Making reliable distributed systems in the presence of software errors JOE Armstrong