Professional Documents
Culture Documents
Abstractions for C#
wait()/notify()
Asynchronous Programming
Asynchronous events and message
passing are increasingly used at all
levels of software systems
e.g. Distributed Applications/components,
GUI, Device Drivers
Many asynchronous messages should be
handled concurrently. Many threads are
used to handle them
Polyphonic C#
C# and .NET
Modern, type-safe, object-oriented
programming language
Very similar to Java
C# programs run on top of the .NET
Framework, which includes a multi-
language execution engine and a rich
collection of class libraries.
– .NET IL
JAVA C#
public void setPoint( int a, int b ) public void setPoint( int a, int b )
{ {
x = a; x = a;
y = b; y = b;
} }
return myString;
}
Trivial Chord = Regular method
public class Buffer
{
public string Get() & public async Put(string s) { return s; }
}
Chord
Thread 1 Thread 2
Put(“1”)
b.Put(“1”); Writeln(b.Get()); Get()
Writeln(b.Get()); b.Put(“2”); Put(“3”)
Writeln(b.Get()); b.Put(“3”);
b.Put(“4”); Writeln(b.Get());
OUTPUT:
1
2
3
4
Buffer buff = new Buffer();
buff.Put(“blue”);
buff.Put(“sky”);
Console.Write(buff.Get());
Console.Write(buff.Get());
bluesky
skyblue
Int x = 7; Int a ;
AddOne(ref x); Random(out a);
class D : C
{
public override async g() { /∗ body3 ∗/ }
}
class E
{
public virtual void f() & private async g() { /∗ body4 ∗/ }
}
Within a particular class – cont’
If any chord-declaration includes a virtual
method m with the override modifier, then
any method n that appears in a chord with
m in the super class containing the
overridden definition of m must also be
overridden in the subclass
RendezVous
class RendezVous
{
private class Thunk
{
int wait() & async reply(int j ) {return j ;}
}
public int f (int i)
{
Thunk t = new Thunk();
af (i, t);
return t.wait();
}
private async af (int i, Thunk t) & public int g(int j )
{
t . reply( j ); // returning to f
return i; // returning to g
}
}
ReaderWriter 1
class ReaderWriter
{
ReaderWriter() {idle();}
public Join2()
{
firstcb = new IntCallback(first);
secondcb = new IntCallback(second);
}
public void wait(out int i, out int j ) & async first(int fst)
& async second(int snd)
{
i = fst; j = snd;
}
}
Active Objects
public abstract class ActiveObject {
public ActiveObject () {
done = false;
mainLoop();
}
async mainLoop() {
while (!done) ProcessMessage();
}
}
public class StockServer : ActiveObject {