Professional Documents
Culture Documents
R. Güntensperger, J. Gutknecht
ETH Zürich
Agenda
1. Overview / History
2. Activity
3. Waiting for conditions
4. Formal dialogs
5. Summary
1. Overview / History
• ROTOR project (2002/2003)
– Main ideas:
• Object-to-object communication by
formal dialogs
• Objects with autonomous, active
behavior from Active Oberon
– SSCLI C# compiler & language
enhancements
• Active C# (2004)
– Consolidation of previous work
2. Activity
• Idea:
– Hide threading mechanism
• Compare:
– Pointer -> Reference
– Thread -> Activity
• Properties:
– New kind of Class-Member
– Provides support for:
• Self-active behavior
class C {
• Communication by formal dialogs
activity {
// activity behavior (optional, see later)
} – Inheritance:
}
• Activities of the base class are
implicitly invoked
Activity variants
Unnamed Named
activity { activity A1 {
Instance-bound
} }
Executed by class Explicitly executed in
constructor static/type context
activity { activity {
… …
lock { lock {
await(condition); condition = true;
} }
… …
} }
Implementation (lock)
• Overloading standard lock
– Choosing context (static/instance)
automatically by compiler
– Signaling possible condition change to (all)
waiting activities
Determined by the
Monitor.Enter(context); compiler:
lock { … } Mapping try { • instance-bound: this
// statements • static: typeof(Class)
}
Signals: finally {
„Change of Monitor.PulseAll(context);
conditions Monitor.Exit(context);
possible“ }
Implementation (await)
• Stop activity until await-condition is true
• Signaling (all) other waiting activities
– Where conditions might have been changed *
• Right before the first Wait
• At end of lock bool waitingAlready = false;
(see before) while(!condition)
{
if(!waitingAlready)
await(condition); Mapping {
Monitor.PulseAll(ref);
waitingAlready = true;
}
* Remark: It is impossible that any
condition change takes place
Monitor.Wait(ref);
inside the await statement }
4. Formal dialogs
• Both dialog partners
– agree to a common syntax
formal grammar
• Described in EBNF-like representation
• Enhancements to EBNF:
– Typed tokens (of a universal set of types)
– Direction keyword Opposite direction
Example (Robot-Protocol):
position <coordX <coordY | battery <batteryLoad | move x y <doneX <doneY
1
in difference to standard activities
Formal dialogs (cont.)
• Formal dialog: Dialog declaration
Vehicle for syntax-controlled
communication between
objects (local/remote) Dialog definition
• Dialog declaration:
Interface for implementation Object
dialog D { k1, k2, k3 }
• Dialog definition:
Implementation of server side
class C {
activity D1 : D { // statements } }
• Use of dialog:
Instantiation by clients Client A Client B
C c = new C();
D myDialog = new c.D1;
Dialog lifecycle
Client side Server side
Create instance
sequence
Exchange tokens
Discard instance