Skip to content

Instantly share code, notes, and snippets.

@mattpodwysocki
Created May 12, 2009 02:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattpodwysocki/110275 to your computer and use it in GitHub Desktop.
Save mattpodwysocki/110275 to your computer and use it in GitHub Desktop.
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