Concurrency vs Parallelism
compile normal program into parallelism program? Hard!
make changes on program as little as possible!
- parallelism ⇒ multi-processor, multi-processes
- concurrency ⇒ single-processor, multi-processes
make write wrong program harder?
Concurrent model
- CSP ⇒ process - process event
- π-calculas ⇒ channel - channel message passing
process algebra
π-calculas is the most complex one, but useful
π-calculas
Send and receive are atomic operation
1 | SquareServer = c(x) . c<x^2> . SquareServer |
Error?
1 | SumServer = C(x) . C(y) . C(x + y) . SumServer |
Give every process unique channel!
1 | SumServer = νd . c<d> . d(x) . d(y) . d<x + y> . SumServer |
More powerful server?
1 | SumServer = (νd . c<d> . d(x) . d(y) . d<x + y> . ∅) | SumServer |
Define such operator
1 | P = !Q = Q | P = Q | Q | Q | ... |
Math server
1 | -- ⊳ select |
MathServer throw select operation? how?
1 | MathServer = νc . ms<c> . worker c | MathServer |
No function call! use a w(orker) channel to pass “c”
1 | MathServer = νc . ms<c> . w<c> | MathServer |
Dinning phylosophers in π-calculas
omit
Basic Rules
identity and association rule
1 | (P | Q) | R ≡ P (Q | R) |
reduction rule
1 | proc = a<x> . P | a(y) . Q → P | Q [x / y] |
1 | w<a> . a<3> . P | w(z) . z(x) . b<x + 3> |
axiom relating restriction and parallel
1 | (νx . P) | Q ≡ νx . (P | Q) if Q not contains x |
Type system in π-calculas
- process is untyped
- channel is typed
Γ ⊢ P
Dual type
$c : (?Int . !Int . ∅)^{⊥} = !Int . ?Int . ∅$
Type inference
$\frac{Γ, x:t, y:s ⊢ P}{Γ, x:?s . t ⊢ x(y) . P}$
$\frac{Γ ⊢ y:s \quad Γ, x:t ⊢ P}{Γ, x:!s . t ⊢ x \langle y . P}$
note x:t not x:t, y:s
$\frac{Γ_{1} ⊢ P \quad Γ_{2} ⊢ Q}{Γ_{1} ∘ Γ_{2} ⊢ P | Q}$
if $x ∈ Γ_{1}$ is $t$
then $x ∈ Γ_{2}$ need to be $t^{⊥}$
type preservation
Γ ⊢ e : τ ∧ e -> e’ ⇒ Γ ⊢ e’ : τ
Γ ⊢ e : τ
- e value
- ∃ e’, e → e’
linear logic
cut rule