#include <concurrency.cvh>
#include <stdio.h>

$gbarrier gbarrier = $gbarrier_create($here, 2);

int main() {
  int a;
  void foo(int id) {
    $barrier b = $barrier_create($here, gbarrier, id);
    $barrier_call(b);
    printf("Hello from thread %d\n", id);
    a=id;
    $barrier_call(b); 
    printf("a=%d\n", a);
    $assert(a==1);
    $barrier_destroy(b);
  }
  $proc p0 = $spawn foo(0);
  $proc p1 = $spawn foo(1);
  $wait(p0);
  $wait(p1);
  $gbarrier_destroy(gbarrier);
}
