Created
May 12, 2009 02:15
-
-
Save mattpodwysocki/110275 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Concurrency; | |
using System.Collections.Generic; | |
using Microsoft.Axum; | |
using System.Concurrency.Messaging; | |
public agent Program : channel Application | |
{ | |
public Program() | |
{ | |
// Wait for our command args | |
var cmdArgs = receive(PrimaryChannel::CommandLine); | |
// Set the iterations to be some number | |
var iters = 3; | |
var chan = Ping.CreateInNewDomain(); | |
chan::HowMany <-- iters; | |
receive(chan::Done); | |
PrimaryChannel::Done <-- Signal.Value; | |
} | |
} | |
public channel PingPongStatus | |
{ | |
input int HowMany; | |
output int Done; | |
Start: { HowMany, Done -> End; } | |
} | |
public agent Ping : channel PingPongStatus | |
{ | |
public Ping() | |
{ | |
var iters = receive(PrimaryChannel::HowMany); | |
var chan = Pong.CreateInNewDomain(); | |
chan::HowMany <-- iters; | |
for (int i = 0; i < iters; i++) | |
{ | |
chan::Ping <-- Signal.Value; | |
receive(chan::Pong); | |
Console.WriteLine("Ping received pong"); | |
} | |
int pongIters = receive(chan::Done); | |
PrimaryChannel::Done <-- 0; | |
} | |
} | |
public channel PingPong | |
{ | |
input int HowMany; | |
output int Done; | |
input Signal Ping; | |
output Signal Pong; | |
} | |
public agent Pong : channel PingPong | |
{ | |
public Pong() | |
{ | |
// Get how many we're supposed to do | |
var iters = receive(PrimaryChannel::HowMany); | |
int i = 0; | |
// Receive our ping and send back our pong | |
for (; i < iters; i++) | |
{ | |
receive(PrimaryChannel::Ping); | |
Console.WriteLine("Pong received ping"); | |
PrimaryChannel::Pong <-- Signal.Value; | |
} | |
PrimaryChannel::Done <-- i; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment