Your SlideShare is downloading. ×
0
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

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

348

Published on

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

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

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
348
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. PISTACHEA π-Calculus Internal Domain Specific Language for Scala
  • 2. • PedroMatiello pmatiello@gmail.com• AnaCristina de Melo acvm@ime.usp.br• http://code.google.com/p/pistache/
  • 3. INTRODUCTION• Pistacheis an implementation of the π-Calculus as a domain specific language hosted in Scala
  • 4. INTRODUCTION• Itprovides π-Calculus’ abstractions for concurrent computation within the Scala programming language
  • 5. π-CALCULUS
  • 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 PrefixP+Q SumP|Q Parallel(νx)P Restriction[x=y].P Match[x≠y].P Mismatch
  • 9. PREFIXES_yx Outputy(x) Input τ Silent
  • 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
  • 11. SCALA
  • 12. • Scalais a general-purpose programming language providing features both of object-oriented and functional programming
  • 13. • Flexible syntax• Statically-typed• Runs on the Java Virtual Machine
  • 14. • Actively-developed• Growing community
  • 15. PISTACHE
  • 16. • Pistacheis an implementation of π-Calculus as an internal Domain Specific Language for Scala
  • 17. AGENT DEFINITIONval P = Agent(...)lazy val recP:Agent = Agent(...)val restrP = Agent { val restrictedName = Name(...) ...}
  • 18. NAMESval name = Name(some_object)val name = Name[Type]name := other_objectvalue = name.value
  • 19. CHANNELSval y = Link[Type] _y~x yxy(x) y(x)
  • 20. SILENT TRANSITIONSval silent = Action{ doSomething() } τ
  • 21. CONCATENATIONval P = Agent { p1 * p2 * Q } P = α.β.Q
  • 22. COMPOSITIONval P = Agent { Q | R | S } P=Q|R|S
  • 23. SUMMATIONval P = Agent { (p1 :: Q) + (p2 :: R) + (p3 :: S) P = αQ + βR + γS}
  • 24. MATCHINGval P = Agent(If (x==y) {Q}) P = [x=y] Q
  • 25. EXAMPLE• The Agents: _ C = (νz) y(p).pz _ S = yx.S P = x(w).α.P• The composition: C|S|P
  • 26. EXAMPLEval y = Link[Link[String]]val x = Link[String]
  • 27. EXAMPLEval 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. EXAMPLEval 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. EXAMPLEval 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. EXAMPLEval 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 emptyWait until y is empty
  • 33. DATA STRUCTUREval P = Agent ( p1 * p2 * p3 * Q )
  • 34. DATA STRUCTUREval P = Agent ( p1 * p2 * p3 * Q )
  • 35. EXECUTIONdef execute(agent:PiObject) { agent match { case ConcatenationAgent(left, right) => ... case CompositionAgent(left, right) => ... ... }}
  • 36. EXECUTIONcase ConcatenationAgent(left, right) => execute(left apply) execute(right apply)
  • 37. EXECUTIONcase CompositionAgent(left, right) => executeInNewThread(left apply) executeInNewThread(right apply)
  • 38. THREAD SPAWNINGdef executeInNewThread(agent:PiObject) { val runnable = new Runnable() { override def run() { execute(agent) } } executor.execute(runnable)}
  • 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 msCachedThreadPool 2 089 ms
  • 41. CONCLUSION• We knew that: • Concurrent programming is hard
  • 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
  • 44. PISTACHE Pedro MatielloAna Cristina de Melo

×