6. • π-Calculus
is a formal language for describing
concurrent computation with dynamic
reconfiguration
7. • Agentscommunicate by exchanging names through
channels (which are also names)
• Connections between agents may change in the
course of the computation
8. AGENTS
0 Nil
α.P Prefix
P+Q Sum
P|Q Parallel
(νx)P Restriction
[x=y].P Match
[x≠y].P Mismatch
10. EXAMPLE
• The Agents:
_
C = (νz) y(p).pz
_
S = yx.S
P = x(w).α.P
• The
composition:
C|S|P
Example adapted from: An Introduction to the pi-Calculus, by Joachim Parrow
27. EXAMPLE
val y = Link[Link[String]]
val x = Link[String]
val C = Agent {
val p = Name[Link[String]]
_
C = (νz) y(p).pz
val z = "message"
y(p) * p~z
}
28. EXAMPLE
val y = Link[Link[String]]
val x = Link[String]
val C = Agent {
val p = Name[Link[String]]
_
S = yx.S
y(p) * p~"message"
}
lazy val S:Agent = Agent { y~x*S }
29. EXAMPLE
val y = Link[Link[String]]
val x = Link[String]
val C = Agent {
val p = Name[Link[String]]
y(p) * p~"message"
}
lazy val S:Agent = Agent { y~x*S }
lazy val P:Agent = Agent {
val w = Name[String]
P = x(w).α.P
val act = Action { println(msg.value) }
x(w) * act * P
}
30. EXAMPLE
val y = Link[Link[String]]
val x = Link[String]
val C = Agent {
val p = Name[Link[String]]
y(p) * p~"message"
}
lazy val S:Agent = Agent { y~x*S }
lazy val P:Agent = Agent {
val msg = Name[String] C|S|P
val act = Action { println(msg.value) }
x(msg) * act * P
}
new ThreadedRunner(C | S | P) start
31. MESSAGE PASSING
• Channels are implemented as shared buffers
• Communication between agents is synchronous
32. MESSAGE PASSING
_
Output yx Input y(x)
Wait until y is empty Wait until y is not empty
Put x on y Put the contents of y in x
Signal y not empty Signal y empty
Wait until y is empty
39. THREAD SPAWNING
• CachedThreadPool
• Caches finished threads
• Reuses cached threads
• Creates new threads if none are available
• Deletesfrom the pool threads that have not been used
reused for 60 seconds
40. THREAD SPAWNING
Strategy Time consumed for 100k agents
new Thread 23 743 ms
CachedThreadPool 2 089 ms
42. CONCLUSION
• We learned that:
• Properabstractions can improve our understanding of
concurrency and concurrent programs
43. CONCLUSION
• We also learned that:
• The
abstractions present in π-Calculus provide a feasible
model for concurrency in actual software programming