linguistic symbiosis between actors and threads
DESCRIPTION
Linguistic Symbiosis between Actors and Threads. Tom Van Cutsem, Stijn Mostinckx, Wolfgang De Meuter. ESUG 2007, LuganoTRANSCRIPT
![Page 1: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/1.jpg)
Linguistic Symbiosis between Actors and Threads
Tom Van Cutsem Stijn Mostinckx Wolfgang De Meuter
Programming Technology LabVrije Universiteit Brussel
Brussels, Belgium
International Conference on Dynamic Languages, August 27th 2007, Lugano
![Page 2: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/2.jpg)
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
![Page 3: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/3.jpg)
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();}
![Page 4: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/4.jpg)
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();}
![Page 5: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/5.jpg)
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
![Page 6: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/6.jpg)
Event loop concurrency
5
Actor
Message queue Event loop
Based on E programming language [Miller05]
![Page 7: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/7.jpg)
Event loop concurrency
5
Actor
Message queue Event loop
‘local’ object
Based on E programming language [Miller05]
![Page 8: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/8.jpg)
Event loop concurrency
5
Actor
Message queue Event loop
‘local’ object
obj
obj.m()
Based on E programming language [Miller05]
![Page 9: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/9.jpg)
Event loop concurrency
5
Actor
Message queue Event loop
‘local’ object ‘remote’ object
Based on E programming language [Miller05]
![Page 10: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/10.jpg)
Event loop concurrency
5
Actor
Message queue Event loop
‘local’ object ‘remote’ object
obj
obj<-m()
Based on E programming language [Miller05]
![Page 11: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/11.jpg)
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]
![Page 12: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/12.jpg)
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);
![Page 13: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/13.jpg)
Actor/Thread Mapping
7
![Page 14: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/14.jpg)
Actor/Thread Mapping
7
?
![Page 15: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/15.jpg)
Actors as Threads
8
Actor
obj
def obj := object: { ... };
aJavaCollection.add(obj);
aJavaCollection
![Page 16: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/16.jpg)
Actors as Threads
8
Actor
obj
def obj := object: { ... };
aJavaCollection.add(obj);
aJavaCollection
add(obj)
![Page 17: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/17.jpg)
Actors as Threads
8
Actor
obj
def obj := object: { ... };
aJavaCollection.add(obj);
aJavaCollection
add(obj)
![Page 18: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/18.jpg)
Actors as Threads
8
Actor
obj
def obj := object: { ... };
aJavaCollection.add(obj);
synchronizedCol
add(obj)
![Page 19: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/19.jpg)
Actors as Threads
9
Actor
obj
def obj := object: { def compareTo(other) { ... }}
aJavaCollection.add(obj);
aJavaCollection
![Page 20: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/20.jpg)
Actors as Threads
9
Actor
obj
def obj := object: { def compareTo(other) { ... }}
aJavaCollection.add(obj);
aJavaCollection
add(obj)
![Page 21: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/21.jpg)
Actors as Threads
9
Actor
obj
def obj := object: { def compareTo(other) { ... }}
aJavaCollection.add(obj);
aJavaCollection
add(obj)
![Page 22: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/22.jpg)
Actors as Threads
9
Actor
obj
def obj := object: { def compareTo(other) { ... }}
aJavaCollection.add(obj);
aJavaCollection
add(obj)
compareTo(obj2)
![Page 23: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/23.jpg)
Actors as Threads
9
Actor
obj
def obj := object: { def compareTo(other) { ... }}
aJavaCollection.add(obj);
aJavaCollection
add(obj)
![Page 24: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/24.jpg)
Threads as Actors
10
def ambientTalkTest := object: { def countTestCases() { ... } def run(result) { ... }}
interface junit.framework.Test { public int countTestCases(); public void run(TestResult r);}
![Page 25: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/25.jpg)
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);}
![Page 26: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/26.jpg)
Actor
ambientTalkTest
suite
Threads as Actors
10
![Page 27: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/27.jpg)
Actor
ambientTalkTest
suite
Threads as Actors
10
run(result)
![Page 28: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/28.jpg)
Actor
ambientTalkTest
suite
Threads as Actors
10
run(result)
![Page 29: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/29.jpg)
Actor
ambientTalkTest
suite
Threads as Actors
10
![Page 30: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/30.jpg)
Actor
ambientTalkTest
suite
Threads as Actors
10
wrapper
![Page 31: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/31.jpg)
Actor
ambientTalkTest
suite
Threads as Actors
10
wrapper
barrier.get()
![Page 32: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/32.jpg)
Actor
ambientTalkTest
suite
Threads as Actors
10
wrapper
barrier.get()
![Page 33: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/33.jpg)
Actor
ambientTalkTest
suite
Threads as Actors
10
wrapper
barrier.get()
![Page 34: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/34.jpg)
Threads as Actors
11
ActionListener l = ...;l.actionPerformed(actionEvent);
def button := Button.new(“Click Me”);button.addActionListener(object: { def actionPerformed(actionEvent) { ... }});
![Page 35: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/35.jpg)
Actor
buttonListener
button
Threads as Actors
11
ActionListener l = ...;l.actionPerformed(actionEvent);
def button := Button.new(“Click Me”);button.addActionListener(object: { def actionPerformed(actionEvent) { ... }});
![Page 36: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/36.jpg)
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) { ... }});
![Page 37: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/37.jpg)
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) { ... }});
![Page 38: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/38.jpg)
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) { ... }});
![Page 39: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/39.jpg)
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) { ... }});
![Page 40: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/40.jpg)
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) { ... }});
![Page 41: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/41.jpg)
Actor
buttonListener
button
Threads as Actors
11
wrapper
interface I extends java.util.EventListener { public void event(...);}
![Page 42: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/42.jpg)
Summary
12
![Page 43: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/43.jpg)
Summary
12
collection.add(obj)
![Page 44: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/44.jpg)
Summary
12
obj.compareTo(obj2)
![Page 45: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/45.jpg)
Summary
12
![Page 46: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/46.jpg)
Summary
12
unitTest.run(reporter)
![Page 47: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/47.jpg)
Summary
12
listener.actionPerformed(ae)
![Page 48: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/48.jpg)
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
![Page 49: Linguistic Symbiosis between Actors and Threads](https://reader033.vdocuments.us/reader033/viewer/2022051210/54b75a864a7959f9168b4573/html5/thumbnails/49.jpg)
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