This document discusses computational models in software engineering, including concurrency models like shared memory and message passing. It covers the actor model, lambda calculus, pi calculus, and join calculus models of computation. Examples are provided of shared memory with synchronization issues, message passing, and how the actor model addresses problems like reference cell access, mutual exclusion, and the dining philosophers. The importance of message passing in object-oriented programming is discussed through a Alan Kay quote.
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. 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)
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
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. 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. λ (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. λ (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) -> Z
f : Z -> ( Z -> Z) and gx : Z -> Z
Example
f(2) = g2, where g2(y) = 2 + y.
f(2)(3) = g2(3) = 2 + 3 = 5
in 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 - ‘first class values’, so function may be
used as the inputs, or be returned as outputs from other functions.
14. π (pi) calculus
• Pi calculus is a formal model for specification, analysis, and
verification 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,b…c}, interaction (reading, writing) is denoted by prefix α.
• A simple interaction between two processes over a channel
a can be modeled as follows in the π calculus: a(x).P | āb.Q
15. Actor model
• Asynchronous communication between nodes
• Every actor has it’s 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.
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. 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. 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
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 efficiently
enough to be useful)” – Alan Kay.
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