linguistic symbiosis between actors and threads
play

Linguistic Symbiosis between Actors and Threads Tom Van Cutsem - PowerPoint PPT Presentation

Linguistic Symbiosis between Actors and Threads Tom Van Cutsem Stijn Mostinckx Wolfgang De Meuter Programming Technology Lab Vrije Universiteit Brussel Brussels, Belgium International Conference on Dynamic Languages, August 27th 2007,


  1. Linguistic Symbiosis between Actors and Threads Tom Van Cutsem Stijn Mostinckx Wolfgang De Meuter Programming Technology Lab Vrije Universiteit Brussel Brussels, Belgium International Conference on Dynamic Languages, August 27th 2007, Lugano

  2. Overview • AmbientTalk: OO DSL for mobile ad hoc networks • Pure event-driven con- currency model (actors [Agha86]) • How to do a safe linguistic symbiosis between actors and threads? 2

  3. Actors vs. Threads actor: { def obj := object: { def m() { ... } } def button := Button. new (“Click Me”); button.addActionListener( object: { def actionPerformed(actionEvent) { obj.m(); } }) obj.m(); } 3

  4. Actors vs. Threads actor: { def obj := object: { def m() { ... } } def button := Button. new (“Click Me”); button.addActionListener( object: { def actionPerformed(actionEvent) { obj.m(); } }) obj.m(); } 3

  5. Event Loop Concurrency • Events are executed serially • Event notification is strictly asynchronous • Event loops should have no shared state Event Event Queue Event Loop Event Handler 4

  6. Event loop concurrency Based on E programming language [Miller05] Actor Message queue Event loop 5

  7. Event loop concurrency Based on E programming language [Miller05] Actor ‘local’ object Message queue Event loop 5

  8. Event loop concurrency Based on E programming language [Miller05] Actor ‘local’ object obj.m() obj Message queue Event loop 5

  9. Event loop concurrency Based on E programming language [Miller05] Actor ‘local’ object ‘remote’ object Message queue Event loop 5

  10. Event loop concurrency Based on E programming language [Miller05] Actor ‘local’ object ‘remote’ object obj<-m() obj Message queue Event loop 5

  11. Event loop concurrency Based on E programming language [Miller05] Actor ‘local’ object ‘remote’ object obj<-m() obj Message queue Event loop Actors cannot cause deadlock No race conditions on objects 5

  12. AmbientTalk/Java Based on Inter-language Reflection [Gybels et al 05] • AmbientTalk is implemented in Java • Data mapping: cfr. JRuby, Jython, JScheme, LuaJava, JPiccola, ... • Tight integration at the syntactic level def Button := jlobby .java.awt.Button; def button := Button. new (“Click Me”); button.addActionListener( object: { def actionPerformed(actionEvent) { ... } }); button.setVisible( true ); 6

  13. Actor/Thread Mapping 7

  14. Actor/Thread Mapping ? 7

  15. Actors as Threads def obj := object: { ... }; aJavaCollection.add(obj); Actor obj aJavaCollection 8

  16. Actors as Threads def obj := object: { ... }; aJavaCollection.add(obj); Actor add(obj) obj aJavaCollection 8

  17. Actors as Threads def obj := object: { ... }; aJavaCollection.add(obj); Actor add(obj) obj aJavaCollection 8

  18. Actors as Threads def obj := object: { ... }; aJavaCollection.add(obj); Actor add(obj) obj synchronizedCol 8

  19. Actors as Threads def obj := object: { def compareTo(other) { ... } } aJavaCollection.add(obj); Actor obj aJavaCollection 9

  20. Actors as Threads def obj := object: { def compareTo(other) { ... } } aJavaCollection.add(obj); Actor add(obj) obj aJavaCollection 9

  21. Actors as Threads def obj := object: { def compareTo(other) { ... } } aJavaCollection.add(obj); Actor add(obj) obj aJavaCollection 9

  22. Actors as Threads def obj := object: { def compareTo(other) { ... } } aJavaCollection.add(obj); Actor compareTo(obj2) add(obj) obj aJavaCollection 9

  23. Actors as Threads def obj := object: { def compareTo(other) { ... } } aJavaCollection.add(obj); Actor add(obj) obj aJavaCollection 9

  24. Threads as Actors interface junit.framework.Test { def ambientTalkTest := object: { public int countTestCases(); def countTestCases() { ... } public void run(TestResult r); def run(result) { ... } } } 10

  25. Threads as Actors interface junit.framework.Test { def ambientTalkTest := object: { public int countTestCases(); def countTestCases() { ... } public void run(TestResult r); def run(result) { ... } } } TestSuite suite = new TestSuite(); ATObject atUnitTest = /* load ambienttalk test */; suite.addTest((Test) wrap(atUnitTest, Test .class )); suite.addTest(aJavaUnitTest); junit.textuit.TestRunner.run(suite); 10

  26. Threads as Actors ambientTalkTest suite Actor 10

  27. Threads as Actors ambientTalkTest run(result) suite Actor 10

  28. Threads as Actors ambientTalkTest run(result) suite Actor 10

  29. Threads as Actors ambientTalkTest suite Actor 10

  30. Threads as Actors ambientTalkTest suite wrapper Actor 10

  31. Threads as Actors ambientTalkTest barrier.get() suite wrapper Actor 10

  32. Threads as Actors ambientTalkTest barrier.get() suite wrapper Actor 10

  33. Threads as Actors ambientTalkTest barrier.get() suite wrapper Actor 10

  34. Threads as Actors def button := Button. new (“Click Me”); ActionListener l = ...; button.addActionListener( object: { l.actionPerformed(actionEvent); def actionPerformed(actionEvent) { ... } }); 11

  35. Threads as Actors def button := Button. new (“Click Me”); ActionListener l = ...; button.addActionListener( object: { l.actionPerformed(actionEvent); def actionPerformed(actionEvent) { ... } }); buttonListener button Actor 11

  36. Threads as Actors def button := Button. new (“Click Me”); ActionListener l = ...; button.addActionListener( object: { l.actionPerformed(actionEvent); def actionPerformed(actionEvent) { ... } }); buttonListener actionPerformed(ae) button Actor 11

  37. Threads as Actors def button := Button. new (“Click Me”); ActionListener l = ...; button.addActionListener( object: { l.actionPerformed(actionEvent); def actionPerformed(actionEvent) { ... } }); buttonListener button wrapper Actor 11

  38. Threads as Actors def button := Button. new (“Click Me”); ActionListener l = ...; button.addActionListener( object: { l.actionPerformed(actionEvent); def actionPerformed(actionEvent) { ... } }); buttonListener button wrapper Actor 11

  39. Threads as Actors def button := Button. new (“Click Me”); ActionListener l = ...; button.addActionListener( object: { l.actionPerformed(actionEvent); def actionPerformed(actionEvent) { ... } }); buttonListener button wrapper Actor 11

  40. Threads as Actors def button := Button. new (“Click Me”); ActionListener l = ...; button.addActionListener( object: { l.actionPerformed(actionEvent); def actionPerformed(actionEvent) { ... } }); buttonListener button wrapper Actor 11

  41. Threads as Actors interface I extends java.util.EventListener { public void event(...); } buttonListener button wrapper Actor 11

  42. Summary 12

  43. Summary collection.add(obj) 12

  44. Summary obj.compareTo(obj2) 12

  45. Summary 12

  46. Summary unitTest.run(reporter) 12

  47. Summary listener.actionPerformed(ae) 12

  48. Experience • AmbientTalk using Java: AWT and Swing for GUI construction • Java using AmbientTalk: JEdit plugin for collaborative text editing • Self/Squeak’s Morphic UI framework in AmbientTalk 13

  49. Conclusions • AmbientTalk: object-oriented (distributed) event-driven programming • Symbiotic Thread/Actor mapping: • AmbientTalk invocations proceed immediately • Automatic synchronization of Java invocations • Support for Java “event notifications” (listeners) http://prog.vub.ac.be/amop 14

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend