#include<collate.cvh>

$gcollator gcollator=$gcollator_create($here, 2);
_Bool start=$false;//, done=$false;
int state[2]={[0]=0, [1]=0};

void updating(int a, int b, int i){
  int v=$pow(a,b);

  state[i]=v;
}


void proc1(){
  $collator collator=$collator_create(gcollator, $here, 0);

  $collate_state cs=$collate_arrives(collator, $here);
  start=$true;
  $collate_departs(collator, cs);
  $free(collator);
}

void proc2(){
  $collator collator=$collator_create(gcollator, $here, 1);
  $collate_state cs;

  $when(start);
  $update(collator) updating(5, 6, 1);
  $update(collator) $pow(3, 4);
  cs = $collate_arrives(collator, $here);
  $collate_departs(collator, cs);
  $free(collator);
}

int main(){
  $proc p[2];

  $atomic{
    p[0]=$spawn proc1();
    p[1]=$spawn proc2();
  }
  $waitall(p, 2);
  $free(gcollator);
}
