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

linguistic symbiosis between actors and threads
SMART_READER_LITE
LIVE PREVIEW

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,


slide-1
SLIDE 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

slide-2
SLIDE 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

slide-3
SLIDE 3

Actors vs. Threads

3

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

  • bj.m();

} })

  • bj.m();

}

slide-4
SLIDE 4

Actors vs. Threads

3

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

  • bj.m();

} })

  • bj.m();

}

slide-5
SLIDE 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

slide-6
SLIDE 6

Event loop concurrency

5

Actor

Message queue

Event loop

Based on E programming language [Miller05]

slide-7
SLIDE 7

Event loop concurrency

5

Actor

Message queue

Event loop

‘local’ object

Based on E programming language [Miller05]

slide-8
SLIDE 8

Event loop concurrency

5

Actor

Message queue

Event loop

‘local’ object

  • bj
  • bj.m()

Based on E programming language [Miller05]

slide-9
SLIDE 9

Event loop concurrency

5

Actor

Message queue

Event loop

‘local’ object ‘remote’ object

Based on E programming language [Miller05]

slide-10
SLIDE 10

Event loop concurrency

5

Actor

Message queue

Event loop

‘local’ object ‘remote’ object

  • bj
  • bj<-m()

Based on E programming language [Miller05]

slide-11
SLIDE 11

Event loop concurrency

5

Actor

Message queue

Event loop

‘local’ object ‘remote’ object

Actors cannot cause deadlock No race conditions on objects

  • bj
  • bj<-m()

Based on E programming language [Miller05]

slide-12
SLIDE 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);

slide-13
SLIDE 13

Actor/Thread Mapping

7

slide-14
SLIDE 14

Actor/Thread Mapping

7

?

slide-15
SLIDE 15

Actors as Threads

8

Actor

  • bj

def obj := object: { ... }; aJavaCollection.add(obj);

aJavaCollection

slide-16
SLIDE 16

Actors as Threads

8

Actor

  • bj

def obj := object: { ... }; aJavaCollection.add(obj);

aJavaCollection add(obj)

slide-17
SLIDE 17

Actors as Threads

8

Actor

  • bj

def obj := object: { ... }; aJavaCollection.add(obj);

aJavaCollection add(obj)

slide-18
SLIDE 18

Actors as Threads

8

Actor

  • bj

def obj := object: { ... }; aJavaCollection.add(obj);

synchronizedCol add(obj)

slide-19
SLIDE 19

Actors as Threads

9

Actor

  • bj

def obj := object: { def compareTo(other) { ... } } aJavaCollection.add(obj);

aJavaCollection

slide-20
SLIDE 20

Actors as Threads

9

Actor

  • bj

def obj := object: { def compareTo(other) { ... } } aJavaCollection.add(obj);

aJavaCollection add(obj)

slide-21
SLIDE 21

Actors as Threads

9

Actor

  • bj

def obj := object: { def compareTo(other) { ... } } aJavaCollection.add(obj);

aJavaCollection add(obj)

slide-22
SLIDE 22

Actors as Threads

9

Actor

  • bj

def obj := object: { def compareTo(other) { ... } } aJavaCollection.add(obj);

aJavaCollection add(obj) compareTo(obj2)

slide-23
SLIDE 23

Actors as Threads

9

Actor

  • bj

def obj := object: { def compareTo(other) { ... } } aJavaCollection.add(obj);

aJavaCollection add(obj)

slide-24
SLIDE 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); }

slide-25
SLIDE 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); }

slide-26
SLIDE 26

Actor

ambientTalkTest suite

Threads as Actors

10

slide-27
SLIDE 27

Actor

ambientTalkTest suite

Threads as Actors

10

run(result)

slide-28
SLIDE 28

Actor

ambientTalkTest suite

Threads as Actors

10

run(result)

slide-29
SLIDE 29

Actor

ambientTalkTest suite

Threads as Actors

10

slide-30
SLIDE 30

Actor

ambientTalkTest suite

Threads as Actors

10

wrapper

slide-31
SLIDE 31

Actor

ambientTalkTest suite

Threads as Actors

10

wrapper barrier.get()

slide-32
SLIDE 32

Actor

ambientTalkTest suite

Threads as Actors

10

wrapper barrier.get()

slide-33
SLIDE 33

Actor

ambientTalkTest suite

Threads as Actors

10

wrapper barrier.get()

slide-34
SLIDE 34

Threads as Actors

11

ActionListener l = ...; l.actionPerformed(actionEvent);

def button := Button.new(“Click Me”); button.addActionListener(object: { def actionPerformed(actionEvent) { ... } });

slide-35
SLIDE 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) { ... } });

slide-36
SLIDE 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) { ... } });

slide-37
SLIDE 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) { ... } });

slide-38
SLIDE 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) { ... } });

slide-39
SLIDE 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) { ... } });

slide-40
SLIDE 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) { ... } });

slide-41
SLIDE 41

Actor

buttonListener button

Threads as Actors

11

wrapper interface I extends java.util.EventListener { public void event(...); }

slide-42
SLIDE 42

Summary

12

slide-43
SLIDE 43

Summary

12

collection.add(obj)

slide-44
SLIDE 44

Summary

12

  • bj.compareTo(obj2)
slide-45
SLIDE 45

Summary

12

slide-46
SLIDE 46

Summary

12

unitTest.run(reporter)

slide-47
SLIDE 47

Summary

12

listener.actionPerformed(ae)

slide-48
SLIDE 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

slide-49
SLIDE 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