#include <stdio.h>
#include "parc.h"

using namespace parc;

pipe<int> chn;

module top {
public:
  int i;
  top() {
    i = 1;
  }

  process p1 {
  start:
    for (; i < 5 ; i++) {
      mt_printf("p1> %d @ %3.3f\n",
                i,MyKern()->Now().D());
      chn.write(&i,1);
    }
  } a;

  process p2 {
    int d,r; 
  start:
    while (CHNS_DEAD != (r = chn.read(&d,1))) mt_printf("p2< %d @ %3.3f\n",
                                                        d,MyKern()->Now().D());
    printf("p2: done\n");
  } b;

};

  process p3 {
    int d,r; 
  start:
    migrate();
    while (CHNS_DEAD != (r = chn.read(&d,1))) mt_printf("p3< %d @ %3.3f\n",
                                                        d,MyKern()->Now().D());
    printf("p3: done\n");
  };


void test()
{
  top t;

  p3 c;

  root()->StartAll();
}

int main(int argc,char **argv)
{
  test();
}