Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Pistache: A π-Calculus Internal Domain Specific Language for Scala

Pedro Matiello
September 26, 2011

Pistache: A π-Calculus Internal Domain Specific Language for Scala

Presented at: XIV Simpósio Brasileiro de Métodos Formais (SBMF 2011), September/2011.

Pedro Matiello

September 26, 2011
Tweet

More Decks by Pedro Matiello

Other Decks in Research

Transcript

  1. • Pistache is an implementation of the π-Calculus as a

    domain specific language hosted in Scala INTRODUCTION
  2. •Agents communicate by exchanging names through channels (which are also

    names) •Connections between agents may change in the course of the computation
  3. AGENTS 0 Nil α.P Prefix P + Q Sum PʛQ

    Parallel (νx)P Restriction [x=y].P Match [x≠y].P Mismatch
  4. • The Agents: C = (νz) y(p).pz S = yx.S

    P = x(w).α.P • The composition: C | S | P & 6 3 \ [ _ _ EXAMPLE Example adapted from: An Introduction to the pi-Calculus, by Joachim Parrow
  5. val P = Agent(...) lazy val recP:Agent = Agent(...) val

    restrP = Agent { val restrictedName = Name(...) ... } AGENT DEFINITION
  6. val name = Name(some_object) val name = Name[Type] name :=

    other_object value = name.value NAMES
  7. val P = Agent { p1 * p2 * Q

    } P = α.β.Q CONCATENATION
  8. val P = Agent { Q | R | S

    } P = Q | R | S COMPOSITION
  9. val P = Agent { (p1 :: Q) + (p2

    :: R) + (p3 :: S) P = αQ + βR + γS } SUMMATION
  10. • The Agents: C = (νz) y(p).pz S = yx.S

    P = x(w).α.P • The composition: C | S | P & 6 3 \ [ _ _ EXAMPLE
  11. val y = Link[Link[String]] val x = Link[String] val C

    = Agent { val p = Name[Link[String]] val z = "message" y(p) * p~z } EXAMPLE C = (νz) y(p).pz _
  12. 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 } EXAMPLE S = yx.S _
  13. 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] val act = Action { println(msg.value) } x(w) * act * P } EXAMPLE P = x(w).α.P
  14. 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] val act = Action { println(msg.value) } x(msg) * act * P } new ThreadedRunner(C | S | P) start EXAMPLE C | S | P
  15. MESSAGE PASSING • Channels are implemented as shared buffers •

    Communication between agents is synchronous
  16. 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 _
  17. val P = Agent ( p1 * p2 * p3

    * Q ) DATA STRUCTURE
  18. val P = Agent ( p1 * p2 * p3

    * Q ) DATA STRUCTURE 3 S &RQFDWHQDWLRQ$JHQW &RQFDWHQDWLRQ3UHIL[ &RQFDWHQDWLRQ3UHIL[ 4 S S
  19. def execute(agent:PiObject) { agent match { case ConcatenationAgent(left, right) =>

    ... case CompositionAgent(left, right) => ... ... } } EXECUTION
  20. def executeInNewThread(agent:PiObject) { val runnable = new Runnable() { override

    def run() { execute(agent) } } executor.execute(runnable) } THREAD SPAWNING
  21. THREAD SPAWNING • CachedThreadPool • Caches finished threads • Reuses

    cached threads • Creates new threads if none are available • Deletes from the pool threads that have not been used reused for 60 seconds
  22. • We learned that: • Proper abstractions can improve our

    understanding of concurrency and concurrent programs CONCLUSION
  23. • We also learned that: • The abstractions present in

    π-Calculus provide a feasible model for concurrency in actual software programming CONCLUSION