SlideShare a Scribd company logo
Computational models in software
engineering
Dmitry Zagorulkin (zagorulkinde@me.com)
Concurrency in practice:
• - Distributed systems;
• - Fault tolerant systems;
• - Mobile systems(mobile phones network, vertices
may connect and disconnect);
• - Parallel systems(running on one node)
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)
Shared memory example
Shared memory example
Shared memory example
• Execution # • Synchronized • Not synchronized
1
Incr: 100000000

Decr: 0
Decr: 67356100

Incr: 67356100
2
Incr: 100000000

Decr: 0
Decr: -88564700

Incr: 1407800
3
Incr: 100000000

Decr: 0
Decr: -86920200

Incr: -1667800
Shared memory
• Advantages:
• easy to write such code
• deterministic behaviour
• Disadvantages:
• wrong waste of computer resources
• locking on resource
• hard to scale such code
Message passing example
Message passing example
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
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.
λ (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;
λ (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.
π (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
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.
Actor model
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;
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.
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
Actor language syntax
Actor model(reference cell problem)
Actor model(mutual exclusion)
Actor model(dining philosophers)
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.
Further Reading
• Programming distributed computing systems (A
foundational approach) Carlos A. Varela
• Making reliable distributed systems in the presence of
software errors JOE Armstrong
Ad

More Related Content

What's hot (20)

Stack and heap allocation
Stack and heap allocationStack and heap allocation
Stack and heap allocation
ankitbhasin23
 
Recursion Lecture in Java
Recursion Lecture in JavaRecursion Lecture in Java
Recursion Lecture in Java
Raffi Khatchadourian
 
Java Foundations: Methods
Java Foundations: MethodsJava Foundations: Methods
Java Foundations: Methods
Svetlin Nakov
 
3 recursion
3 recursion3 recursion
3 recursion
Nguync91368
 
06 linked list
06 linked list06 linked list
06 linked list
Rajan Gautam
 
Advanced data structures slide 2 2+
Advanced data structures slide 2 2+Advanced data structures slide 2 2+
Advanced data structures slide 2 2+
jomerson remorosa
 
13 recursion-120712074623-phpapp02
13 recursion-120712074623-phpapp0213 recursion-120712074623-phpapp02
13 recursion-120712074623-phpapp02
Abdul Samee
 
StringTokenizer in java
StringTokenizer in javaStringTokenizer in java
StringTokenizer in java
Muthukumaran Subramanian
 
13. Java text processing
13.  Java text processing13.  Java text processing
13. Java text processing
Intro C# Book
 
Java Foundations: Data Types and Type Conversion
Java Foundations: Data Types and Type ConversionJava Foundations: Data Types and Type Conversion
Java Foundations: Data Types and Type Conversion
Svetlin Nakov
 
Stack and Heap
Stack and HeapStack and Heap
Stack and Heap
baabtra.com - No. 1 supplier of quality freshers
 
Cpphtp4 ppt 03
Cpphtp4 ppt 03Cpphtp4 ppt 03
Cpphtp4 ppt 03
sanya6900
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
Mohammad Tawfik
 
18. Dictionaries, Hash-Tables and Set
18. Dictionaries, Hash-Tables and Set18. Dictionaries, Hash-Tables and Set
18. Dictionaries, Hash-Tables and Set
Intro C# Book
 
C++ Standard Template Library
C++ Standard Template LibraryC++ Standard Template Library
C++ Standard Template Library
Ilio Catallo
 
(Recursion)ads
(Recursion)ads(Recursion)ads
(Recursion)ads
Ravi Rao
 
Java Foundations: Arrays
Java Foundations: ArraysJava Foundations: Arrays
Java Foundations: Arrays
Svetlin Nakov
 
Core java day2
Core java day2Core java day2
Core java day2
Soham Sengupta
 
Method overloading in java
Method overloading in javaMethod overloading in java
Method overloading in java
RithicaManiarasan
 
Functions reading passage
Functions reading passageFunctions reading passage
Functions reading passage
bweldon
 

Similar to Computational models (20)

Clojure intro
Clojure introClojure intro
Clojure intro
Basav Nagur
 
Scala for Machine Learning
Scala for Machine LearningScala for Machine Learning
Scala for Machine Learning
Patrick Nicolas
 
deep learning UNIT-1 Introduction Part-1.ppt
deep learning UNIT-1 Introduction Part-1.pptdeep learning UNIT-1 Introduction Part-1.ppt
deep learning UNIT-1 Introduction Part-1.ppt
shashikanthsana
 
Probabilistic programming2
Probabilistic programming2Probabilistic programming2
Probabilistic programming2
bredelings
 
Recurrent Neural Networks, LSTM and GRU
Recurrent Neural Networks, LSTM and GRURecurrent Neural Networks, LSTM and GRU
Recurrent Neural Networks, LSTM and GRU
ananth
 
Accelerating Key Bioinformatics Tasks 100-fold by Improving Memory Access
Accelerating Key Bioinformatics Tasks 100-fold by Improving Memory AccessAccelerating Key Bioinformatics Tasks 100-fold by Improving Memory Access
Accelerating Key Bioinformatics Tasks 100-fold by Improving Memory Access
Igor Sfiligoi
 
Programming Language Memory Models: What do Shared Variables Mean?
Programming Language Memory Models: What do Shared Variables Mean?Programming Language Memory Models: What do Shared Variables Mean?
Programming Language Memory Models: What do Shared Variables Mean?
greenwop
 
Software Architectures, Week 2 - Decomposition techniques
Software Architectures, Week 2 - Decomposition techniquesSoftware Architectures, Week 2 - Decomposition techniques
Software Architectures, Week 2 - Decomposition techniques
Angelos Kapsimanis
 
S-CUBE LP: Executing the HOCL: Concept of a Chemical Interpreter
S-CUBE LP: Executing the HOCL: Concept of a Chemical InterpreterS-CUBE LP: Executing the HOCL: Concept of a Chemical Interpreter
S-CUBE LP: Executing the HOCL: Concept of a Chemical Interpreter
virtual-campus
 
[Paper Reading] Attention is All You Need
[Paper Reading] Attention is All You Need[Paper Reading] Attention is All You Need
[Paper Reading] Attention is All You Need
Daiki Tanaka
 
The theory of concurrent programming for a seasoned programmer
The theory of concurrent programming for a seasoned programmerThe theory of concurrent programming for a seasoned programmer
The theory of concurrent programming for a seasoned programmer
Roman Elizarov
 
Elixir
ElixirElixir
Elixir
Fuat Buğra AYDIN
 
Hoard_2022AIM1001.pptx.pdf
Hoard_2022AIM1001.pptx.pdfHoard_2022AIM1001.pptx.pdf
Hoard_2022AIM1001.pptx.pdf
AshutoshKumar437302
 
P J020
P J020P J020
P J020
Universidad de Occidente
 
Ch-7-Part-2-Distributed-System.pptx
Ch-7-Part-2-Distributed-System.pptxCh-7-Part-2-Distributed-System.pptx
Ch-7-Part-2-Distributed-System.pptx
Kabindra Koirala
 
MATLAB Programming
MATLAB Programming MATLAB Programming
MATLAB Programming
محمدعبد الحى
 
Presentation of GetTogether on Functional Programming
Presentation of GetTogether on Functional ProgrammingPresentation of GetTogether on Functional Programming
Presentation of GetTogether on Functional Programming
Filip De Sutter
 
A Survey of Concurrency Constructs
A Survey of Concurrency ConstructsA Survey of Concurrency Constructs
A Survey of Concurrency Constructs
Ted Leung
 
Fuel Up JavaScript with Functional Programming
Fuel Up JavaScript with Functional ProgrammingFuel Up JavaScript with Functional Programming
Fuel Up JavaScript with Functional Programming
Shine Xavier
 
Gráficas en python
Gráficas en python Gráficas en python
Gráficas en python
Jhon Valle
 
Scala for Machine Learning
Scala for Machine LearningScala for Machine Learning
Scala for Machine Learning
Patrick Nicolas
 
deep learning UNIT-1 Introduction Part-1.ppt
deep learning UNIT-1 Introduction Part-1.pptdeep learning UNIT-1 Introduction Part-1.ppt
deep learning UNIT-1 Introduction Part-1.ppt
shashikanthsana
 
Probabilistic programming2
Probabilistic programming2Probabilistic programming2
Probabilistic programming2
bredelings
 
Recurrent Neural Networks, LSTM and GRU
Recurrent Neural Networks, LSTM and GRURecurrent Neural Networks, LSTM and GRU
Recurrent Neural Networks, LSTM and GRU
ananth
 
Accelerating Key Bioinformatics Tasks 100-fold by Improving Memory Access
Accelerating Key Bioinformatics Tasks 100-fold by Improving Memory AccessAccelerating Key Bioinformatics Tasks 100-fold by Improving Memory Access
Accelerating Key Bioinformatics Tasks 100-fold by Improving Memory Access
Igor Sfiligoi
 
Programming Language Memory Models: What do Shared Variables Mean?
Programming Language Memory Models: What do Shared Variables Mean?Programming Language Memory Models: What do Shared Variables Mean?
Programming Language Memory Models: What do Shared Variables Mean?
greenwop
 
Software Architectures, Week 2 - Decomposition techniques
Software Architectures, Week 2 - Decomposition techniquesSoftware Architectures, Week 2 - Decomposition techniques
Software Architectures, Week 2 - Decomposition techniques
Angelos Kapsimanis
 
S-CUBE LP: Executing the HOCL: Concept of a Chemical Interpreter
S-CUBE LP: Executing the HOCL: Concept of a Chemical InterpreterS-CUBE LP: Executing the HOCL: Concept of a Chemical Interpreter
S-CUBE LP: Executing the HOCL: Concept of a Chemical Interpreter
virtual-campus
 
[Paper Reading] Attention is All You Need
[Paper Reading] Attention is All You Need[Paper Reading] Attention is All You Need
[Paper Reading] Attention is All You Need
Daiki Tanaka
 
The theory of concurrent programming for a seasoned programmer
The theory of concurrent programming for a seasoned programmerThe theory of concurrent programming for a seasoned programmer
The theory of concurrent programming for a seasoned programmer
Roman Elizarov
 
Ch-7-Part-2-Distributed-System.pptx
Ch-7-Part-2-Distributed-System.pptxCh-7-Part-2-Distributed-System.pptx
Ch-7-Part-2-Distributed-System.pptx
Kabindra Koirala
 
Presentation of GetTogether on Functional Programming
Presentation of GetTogether on Functional ProgrammingPresentation of GetTogether on Functional Programming
Presentation of GetTogether on Functional Programming
Filip De Sutter
 
A Survey of Concurrency Constructs
A Survey of Concurrency ConstructsA Survey of Concurrency Constructs
A Survey of Concurrency Constructs
Ted Leung
 
Fuel Up JavaScript with Functional Programming
Fuel Up JavaScript with Functional ProgrammingFuel Up JavaScript with Functional Programming
Fuel Up JavaScript with Functional Programming
Shine Xavier
 
Gráficas en python
Gráficas en python Gráficas en python
Gráficas en python
Jhon Valle
 
Ad

Recently uploaded (20)

A Massive Black Hole 0.8kpc from the Host Nucleus Revealed by the Offset Tida...
A Massive Black Hole 0.8kpc from the Host Nucleus Revealed by the Offset Tida...A Massive Black Hole 0.8kpc from the Host Nucleus Revealed by the Offset Tida...
A Massive Black Hole 0.8kpc from the Host Nucleus Revealed by the Offset Tida...
Sérgio Sacani
 
Discrete choice experiments: Environmental Improvements to Airthrey Loch Lake...
Discrete choice experiments: Environmental Improvements to Airthrey Loch Lake...Discrete choice experiments: Environmental Improvements to Airthrey Loch Lake...
Discrete choice experiments: Environmental Improvements to Airthrey Loch Lake...
Professional Content Writing's
 
External Application in Homoeopathy- Definition,Scope and Types.
External Application  in Homoeopathy- Definition,Scope and Types.External Application  in Homoeopathy- Definition,Scope and Types.
External Application in Homoeopathy- Definition,Scope and Types.
AdharshnaPatrick
 
Sleep_physiology_types_duration_underlying mech.
Sleep_physiology_types_duration_underlying mech.Sleep_physiology_types_duration_underlying mech.
Sleep_physiology_types_duration_underlying mech.
klynct
 
Applications of Radioisotopes in Cancer Research.pptx
Applications of Radioisotopes in Cancer Research.pptxApplications of Radioisotopes in Cancer Research.pptx
Applications of Radioisotopes in Cancer Research.pptx
MahitaLaveti
 
Preclinical Advances in Nuclear Neurology.pptx
Preclinical Advances in Nuclear Neurology.pptxPreclinical Advances in Nuclear Neurology.pptx
Preclinical Advances in Nuclear Neurology.pptx
MahitaLaveti
 
Black hole and its division and categories
Black hole and its division and categoriesBlack hole and its division and categories
Black hole and its division and categories
MSafiullahALawi
 
Hypothalamus_structure_nuclei_ functions.pptx
Hypothalamus_structure_nuclei_ functions.pptxHypothalamus_structure_nuclei_ functions.pptx
Hypothalamus_structure_nuclei_ functions.pptx
klynct
 
Siver Nanoparticles syntheisis, mechanism, Antibacterial activity.pptx
Siver Nanoparticles syntheisis, mechanism, Antibacterial activity.pptxSiver Nanoparticles syntheisis, mechanism, Antibacterial activity.pptx
Siver Nanoparticles syntheisis, mechanism, Antibacterial activity.pptx
PriyaAntil3
 
Evidence for a polar circumbinary exoplanet orbiting a pair of eclipsing brow...
Evidence for a polar circumbinary exoplanet orbiting a pair of eclipsing brow...Evidence for a polar circumbinary exoplanet orbiting a pair of eclipsing brow...
Evidence for a polar circumbinary exoplanet orbiting a pair of eclipsing brow...
Sérgio Sacani
 
Anti fungal agents Medicinal Chemistry III
Anti fungal agents Medicinal Chemistry  IIIAnti fungal agents Medicinal Chemistry  III
Anti fungal agents Medicinal Chemistry III
HRUTUJA WAGH
 
CORONARY ARTERY BYPASS GRAFTING (1).pptx
CORONARY ARTERY BYPASS GRAFTING (1).pptxCORONARY ARTERY BYPASS GRAFTING (1).pptx
CORONARY ARTERY BYPASS GRAFTING (1).pptx
DharaniJajula
 
Fatigue and its management in aviation medicine
Fatigue and its management in aviation medicineFatigue and its management in aviation medicine
Fatigue and its management in aviation medicine
ImranJewel2
 
Issues in using AI in academic publishing.pdf
Issues in using AI in academic publishing.pdfIssues in using AI in academic publishing.pdf
Issues in using AI in academic publishing.pdf
Angelo Salatino
 
What Are Dendritic Cells and Their Role in Immunobiology?
What Are Dendritic Cells and Their Role in Immunobiology?What Are Dendritic Cells and Their Role in Immunobiology?
What Are Dendritic Cells and Their Role in Immunobiology?
Kosheeka : Primary Cells for Research
 
Eric Schott- Environment, Animal and Human Health (3).pptx
Eric Schott- Environment, Animal and Human Health (3).pptxEric Schott- Environment, Animal and Human Health (3).pptx
Eric Schott- Environment, Animal and Human Health (3).pptx
ttalbert1
 
Reticular formation_groups_organization_
Reticular formation_groups_organization_Reticular formation_groups_organization_
Reticular formation_groups_organization_
klynct
 
AP 2024 Unit 1 Updated Chemistry of Life
AP 2024 Unit 1 Updated Chemistry of LifeAP 2024 Unit 1 Updated Chemistry of Life
AP 2024 Unit 1 Updated Chemistry of Life
mseileenlinden
 
Freshwater Biome Types, Characteristics and Factors
Freshwater Biome Types, Characteristics and FactorsFreshwater Biome Types, Characteristics and Factors
Freshwater Biome Types, Characteristics and Factors
mytriplemonlineshop
 
Pharmacologically active constituents.pdf
Pharmacologically active constituents.pdfPharmacologically active constituents.pdf
Pharmacologically active constituents.pdf
Nistarini College, Purulia (W.B) India
 
A Massive Black Hole 0.8kpc from the Host Nucleus Revealed by the Offset Tida...
A Massive Black Hole 0.8kpc from the Host Nucleus Revealed by the Offset Tida...A Massive Black Hole 0.8kpc from the Host Nucleus Revealed by the Offset Tida...
A Massive Black Hole 0.8kpc from the Host Nucleus Revealed by the Offset Tida...
Sérgio Sacani
 
Discrete choice experiments: Environmental Improvements to Airthrey Loch Lake...
Discrete choice experiments: Environmental Improvements to Airthrey Loch Lake...Discrete choice experiments: Environmental Improvements to Airthrey Loch Lake...
Discrete choice experiments: Environmental Improvements to Airthrey Loch Lake...
Professional Content Writing's
 
External Application in Homoeopathy- Definition,Scope and Types.
External Application  in Homoeopathy- Definition,Scope and Types.External Application  in Homoeopathy- Definition,Scope and Types.
External Application in Homoeopathy- Definition,Scope and Types.
AdharshnaPatrick
 
Sleep_physiology_types_duration_underlying mech.
Sleep_physiology_types_duration_underlying mech.Sleep_physiology_types_duration_underlying mech.
Sleep_physiology_types_duration_underlying mech.
klynct
 
Applications of Radioisotopes in Cancer Research.pptx
Applications of Radioisotopes in Cancer Research.pptxApplications of Radioisotopes in Cancer Research.pptx
Applications of Radioisotopes in Cancer Research.pptx
MahitaLaveti
 
Preclinical Advances in Nuclear Neurology.pptx
Preclinical Advances in Nuclear Neurology.pptxPreclinical Advances in Nuclear Neurology.pptx
Preclinical Advances in Nuclear Neurology.pptx
MahitaLaveti
 
Black hole and its division and categories
Black hole and its division and categoriesBlack hole and its division and categories
Black hole and its division and categories
MSafiullahALawi
 
Hypothalamus_structure_nuclei_ functions.pptx
Hypothalamus_structure_nuclei_ functions.pptxHypothalamus_structure_nuclei_ functions.pptx
Hypothalamus_structure_nuclei_ functions.pptx
klynct
 
Siver Nanoparticles syntheisis, mechanism, Antibacterial activity.pptx
Siver Nanoparticles syntheisis, mechanism, Antibacterial activity.pptxSiver Nanoparticles syntheisis, mechanism, Antibacterial activity.pptx
Siver Nanoparticles syntheisis, mechanism, Antibacterial activity.pptx
PriyaAntil3
 
Evidence for a polar circumbinary exoplanet orbiting a pair of eclipsing brow...
Evidence for a polar circumbinary exoplanet orbiting a pair of eclipsing brow...Evidence for a polar circumbinary exoplanet orbiting a pair of eclipsing brow...
Evidence for a polar circumbinary exoplanet orbiting a pair of eclipsing brow...
Sérgio Sacani
 
Anti fungal agents Medicinal Chemistry III
Anti fungal agents Medicinal Chemistry  IIIAnti fungal agents Medicinal Chemistry  III
Anti fungal agents Medicinal Chemistry III
HRUTUJA WAGH
 
CORONARY ARTERY BYPASS GRAFTING (1).pptx
CORONARY ARTERY BYPASS GRAFTING (1).pptxCORONARY ARTERY BYPASS GRAFTING (1).pptx
CORONARY ARTERY BYPASS GRAFTING (1).pptx
DharaniJajula
 
Fatigue and its management in aviation medicine
Fatigue and its management in aviation medicineFatigue and its management in aviation medicine
Fatigue and its management in aviation medicine
ImranJewel2
 
Issues in using AI in academic publishing.pdf
Issues in using AI in academic publishing.pdfIssues in using AI in academic publishing.pdf
Issues in using AI in academic publishing.pdf
Angelo Salatino
 
Eric Schott- Environment, Animal and Human Health (3).pptx
Eric Schott- Environment, Animal and Human Health (3).pptxEric Schott- Environment, Animal and Human Health (3).pptx
Eric Schott- Environment, Animal and Human Health (3).pptx
ttalbert1
 
Reticular formation_groups_organization_
Reticular formation_groups_organization_Reticular formation_groups_organization_
Reticular formation_groups_organization_
klynct
 
AP 2024 Unit 1 Updated Chemistry of Life
AP 2024 Unit 1 Updated Chemistry of LifeAP 2024 Unit 1 Updated Chemistry of Life
AP 2024 Unit 1 Updated Chemistry of Life
mseileenlinden
 
Freshwater Biome Types, Characteristics and Factors
Freshwater Biome Types, Characteristics and FactorsFreshwater Biome Types, Characteristics and Factors
Freshwater Biome Types, Characteristics and Factors
mytriplemonlineshop
 
Ad

Computational models

  • 1. Computational models in software engineering Dmitry Zagorulkin (zagorulkinde@me.com)
  • 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)
  • 6. Shared memory example • Execution # • Synchronized • Not synchronized 1 Incr: 100000000 Decr: 0 Decr: 67356100 Incr: 67356100 2 Incr: 100000000 Decr: 0 Decr: -88564700 Incr: 1407800 3 Incr: 100000000 Decr: 0 Decr: -86920200 Incr: -1667800
  • 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
  翻译: