Your SlideShare is downloading. ×
0
Linguistic Symbiosis between
Actors and Threads
TomVan Cutsem Stijn Mostinckx Wolfgang De Meuter
Programming Technology La...
Overview
• AmbientTalk: OO DSL for
mobile ad hoc networks
• Pure event-driven con-
currency model (actors
[Agha86])
• How ...
Actors vs.Threads
3
actor: {
def obj := object: {
def m() { ... }
}
def button := Button.new(“Click Me”);
button.addAction...
Actors vs.Threads
3
actor: {
def obj := object: {
def m() { ... }
}
def button := Button.new(“Click Me”);
button.addAction...
Event Loop Concurrency
• Events are executed serially
• Event notification is strictly asynchronous
• Event loops should ha...
Event loop concurrency
5
Actor
Message queue Event loop
Based on E programming language [Miller05]
Event loop concurrency
5
Actor
Message queue Event loop
‘local’ object
Based on E programming language [Miller05]
Event loop concurrency
5
Actor
Message queue Event loop
‘local’ object
obj
obj.m()
Based on E programming language [Miller...
Event loop concurrency
5
Actor
Message queue Event loop
‘local’ object ‘remote’ object
Based on E programming language [Mi...
Event loop concurrency
5
Actor
Message queue Event loop
‘local’ object ‘remote’ object
obj
obj<-m()
Based on E programming...
Event loop concurrency
5
Actor
Message queue Event loop
‘local’ object ‘remote’ object
Actors cannot cause deadlock
No rac...
AmbientTalk/Java
• AmbientTalk is implemented in Java
• Data mapping: cfr. JRuby, Jython, JScheme,
LuaJava, JPiccola, ...
...
Actor/Thread Mapping
7
Actor/Thread Mapping
7
?
Actors as Threads
8
Actor
obj
def obj := object: { ... };
aJavaCollection.add(obj);
aJavaCollection
Actors as Threads
8
Actor
obj
def obj := object: { ... };
aJavaCollection.add(obj);
aJavaCollection
add(obj)
Actors as Threads
8
Actor
obj
def obj := object: { ... };
aJavaCollection.add(obj);
aJavaCollection
add(obj)
Actors as Threads
8
Actor
obj
def obj := object: { ... };
aJavaCollection.add(obj);
synchronizedCol
add(obj)
Actors as Threads
9
Actor
obj
def obj := object: {
def compareTo(other) { ... }
}
aJavaCollection.add(obj);
aJavaCollection
Actors as Threads
9
Actor
obj
def obj := object: {
def compareTo(other) { ... }
}
aJavaCollection.add(obj);
aJavaCollectio...
Actors as Threads
9
Actor
obj
def obj := object: {
def compareTo(other) { ... }
}
aJavaCollection.add(obj);
aJavaCollectio...
Actors as Threads
9
Actor
obj
def obj := object: {
def compareTo(other) { ... }
}
aJavaCollection.add(obj);
aJavaCollectio...
Actors as Threads
9
Actor
obj
def obj := object: {
def compareTo(other) { ... }
}
aJavaCollection.add(obj);
aJavaCollectio...
Threads as Actors
10
def ambientTalkTest := object: {
def countTestCases() { ... }
def run(result) { ... }
}
interface jun...
Threads as Actors
10
def ambientTalkTest := object: {
def countTestCases() { ... }
def run(result) { ... }
}
TestSuite sui...
Actor
ambientTalkTest
suite
Threads as Actors
10
Actor
ambientTalkTest
suite
Threads as Actors
10
run(result)
Actor
ambientTalkTest
suite
Threads as Actors
10
run(result)
Actor
ambientTalkTest
suite
Threads as Actors
10
Actor
ambientTalkTest
suite
Threads as Actors
10
wrapper
Actor
ambientTalkTest
suite
Threads as Actors
10
wrapper
barrier.get()
Actor
ambientTalkTest
suite
Threads as Actors
10
wrapper
barrier.get()
Actor
ambientTalkTest
suite
Threads as Actors
10
wrapper
barrier.get()
Threads as Actors
11
ActionListener l = ...;
l.actionPerformed(actionEvent);
def button := Button.new(“Click Me”);
button....
Actor
buttonListener
button
Threads as Actors
11
ActionListener l = ...;
l.actionPerformed(actionEvent);
def button := But...
Actor
buttonListener
button
Threads as Actors
11
actionPerformed(ae)
ActionListener l = ...;
l.actionPerformed(actionEvent...
Actor
buttonListener
button
Threads as Actors
11
ActionListener l = ...;
l.actionPerformed(actionEvent);
wrapper
def butto...
Actor
buttonListener
button
Threads as Actors
11
ActionListener l = ...;
l.actionPerformed(actionEvent);
wrapper
def butto...
Actor
buttonListener
button
Threads as Actors
11
ActionListener l = ...;
l.actionPerformed(actionEvent);
wrapper
def butto...
Actor
buttonListener
button
Threads as Actors
11
ActionListener l = ...;
l.actionPerformed(actionEvent);
wrapper
def butto...
Actor
buttonListener
button
Threads as Actors
11
wrapper
interface I extends java.util.EventListener {
public void event(....
Summary
12
Summary
12
collection.add(obj)
Summary
12
obj.compareTo(obj2)
Summary
12
Summary
12
unitTest.run(reporter)
Summary
12
listener.actionPerformed(ae)
Experience
• AmbientTalk using Java:AWT and Swing for
GUI construction
• Java using AmbientTalk: JEdit plugin for
collabor...
Conclusions
• AmbientTalk: object-oriented (distributed)
event-driven programming
• Symbiotic Thread/Actor mapping:
• Ambi...
Upcoming SlideShare
Loading in...5
×

Linguistic Symbiosis between Actors and Threads

458

Published on

Linguistic Symbiosis between Actors and Threads. Tom Van Cutsem, Stijn Mostinckx, Wolfgang De Meuter. ESUG 2007, Lugano

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
458
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Linguistic Symbiosis between Actors and Threads"

  1. 1. Linguistic Symbiosis between Actors and Threads TomVan Cutsem Stijn Mostinckx Wolfgang De Meuter Programming Technology Lab Vrije Universiteit Brussel Brussels, Belgium International Conference on Dynamic Languages,August 27th 2007, Lugano
  2. 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. 3. Actors vs.Threads 3 actor: { def obj := object: { def m() { ... } } def button := Button.new(“Click Me”); button.addActionListener(object: { def actionPerformed(actionEvent) { obj.m(); } }) obj.m(); }
  4. 4. Actors vs.Threads 3 actor: { def obj := object: { def m() { ... } } def button := Button.new(“Click Me”); button.addActionListener(object: { def actionPerformed(actionEvent) { obj.m(); } }) obj.m(); }
  5. 5. Event Loop Concurrency • Events are executed serially • Event notification is strictly asynchronous • Event loops should have no shared state 4 Event Event Queue Event Loop Event Handler
  6. 6. Event loop concurrency 5 Actor Message queue Event loop Based on E programming language [Miller05]
  7. 7. Event loop concurrency 5 Actor Message queue Event loop ‘local’ object Based on E programming language [Miller05]
  8. 8. Event loop concurrency 5 Actor Message queue Event loop ‘local’ object obj obj.m() Based on E programming language [Miller05]
  9. 9. Event loop concurrency 5 Actor Message queue Event loop ‘local’ object ‘remote’ object Based on E programming language [Miller05]
  10. 10. Event loop concurrency 5 Actor Message queue Event loop ‘local’ object ‘remote’ object obj obj<-m() Based on E programming language [Miller05]
  11. 11. Event loop concurrency 5 Actor Message queue Event loop ‘local’ object ‘remote’ object Actors cannot cause deadlock No race conditions on objects obj obj<-m() Based on E programming language [Miller05]
  12. 12. AmbientTalk/Java • AmbientTalk is implemented in Java • Data mapping: cfr. JRuby, Jython, JScheme, LuaJava, JPiccola, ... • Tight integration at the syntactic level 6 Based on Inter-language Reflection [Gybels et al 05] def Button := jlobby.java.awt.Button; def button := Button.new(“Click Me”); button.addActionListener(object: { def actionPerformed(actionEvent) { ... } }); button.setVisible(true);
  13. 13. Actor/Thread Mapping 7
  14. 14. Actor/Thread Mapping 7 ?
  15. 15. Actors as Threads 8 Actor obj def obj := object: { ... }; aJavaCollection.add(obj); aJavaCollection
  16. 16. Actors as Threads 8 Actor obj def obj := object: { ... }; aJavaCollection.add(obj); aJavaCollection add(obj)
  17. 17. Actors as Threads 8 Actor obj def obj := object: { ... }; aJavaCollection.add(obj); aJavaCollection add(obj)
  18. 18. Actors as Threads 8 Actor obj def obj := object: { ... }; aJavaCollection.add(obj); synchronizedCol add(obj)
  19. 19. Actors as Threads 9 Actor obj def obj := object: { def compareTo(other) { ... } } aJavaCollection.add(obj); aJavaCollection
  20. 20. Actors as Threads 9 Actor obj def obj := object: { def compareTo(other) { ... } } aJavaCollection.add(obj); aJavaCollection add(obj)
  21. 21. Actors as Threads 9 Actor obj def obj := object: { def compareTo(other) { ... } } aJavaCollection.add(obj); aJavaCollection add(obj)
  22. 22. Actors as Threads 9 Actor obj def obj := object: { def compareTo(other) { ... } } aJavaCollection.add(obj); aJavaCollection add(obj) compareTo(obj2)
  23. 23. Actors as Threads 9 Actor obj def obj := object: { def compareTo(other) { ... } } aJavaCollection.add(obj); aJavaCollection add(obj)
  24. 24. Threads as Actors 10 def ambientTalkTest := object: { def countTestCases() { ... } def run(result) { ... } } interface junit.framework.Test { public int countTestCases(); public void run(TestResult r); }
  25. 25. Threads as Actors 10 def ambientTalkTest := object: { def countTestCases() { ... } 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); interface junit.framework.Test { public int countTestCases(); public void run(TestResult r); }
  26. 26. Actor ambientTalkTest suite Threads as Actors 10
  27. 27. Actor ambientTalkTest suite Threads as Actors 10 run(result)
  28. 28. Actor ambientTalkTest suite Threads as Actors 10 run(result)
  29. 29. Actor ambientTalkTest suite Threads as Actors 10
  30. 30. Actor ambientTalkTest suite Threads as Actors 10 wrapper
  31. 31. Actor ambientTalkTest suite Threads as Actors 10 wrapper barrier.get()
  32. 32. Actor ambientTalkTest suite Threads as Actors 10 wrapper barrier.get()
  33. 33. Actor ambientTalkTest suite Threads as Actors 10 wrapper barrier.get()
  34. 34. Threads as Actors 11 ActionListener l = ...; l.actionPerformed(actionEvent); def button := Button.new(“Click Me”); button.addActionListener(object: { def actionPerformed(actionEvent) { ... } });
  35. 35. Actor buttonListener button Threads as Actors 11 ActionListener l = ...; l.actionPerformed(actionEvent); def button := Button.new(“Click Me”); button.addActionListener(object: { def actionPerformed(actionEvent) { ... } });
  36. 36. Actor buttonListener button Threads as Actors 11 actionPerformed(ae) ActionListener l = ...; l.actionPerformed(actionEvent); def button := Button.new(“Click Me”); button.addActionListener(object: { def actionPerformed(actionEvent) { ... } });
  37. 37. Actor buttonListener button Threads as Actors 11 ActionListener l = ...; l.actionPerformed(actionEvent); wrapper def button := Button.new(“Click Me”); button.addActionListener(object: { def actionPerformed(actionEvent) { ... } });
  38. 38. Actor buttonListener button Threads as Actors 11 ActionListener l = ...; l.actionPerformed(actionEvent); wrapper def button := Button.new(“Click Me”); button.addActionListener(object: { def actionPerformed(actionEvent) { ... } });
  39. 39. Actor buttonListener button Threads as Actors 11 ActionListener l = ...; l.actionPerformed(actionEvent); wrapper def button := Button.new(“Click Me”); button.addActionListener(object: { def actionPerformed(actionEvent) { ... } });
  40. 40. Actor buttonListener button Threads as Actors 11 ActionListener l = ...; l.actionPerformed(actionEvent); wrapper def button := Button.new(“Click Me”); button.addActionListener(object: { def actionPerformed(actionEvent) { ... } });
  41. 41. Actor buttonListener button Threads as Actors 11 wrapper interface I extends java.util.EventListener { public void event(...); }
  42. 42. Summary 12
  43. 43. Summary 12 collection.add(obj)
  44. 44. Summary 12 obj.compareTo(obj2)
  45. 45. Summary 12
  46. 46. Summary 12 unitTest.run(reporter)
  47. 47. Summary 12 listener.actionPerformed(ae)
  48. 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. 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) 14 http://prog.vub.ac.be/amop
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×