#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <pthread.h>
#include "counter.h"

counter_t ctr;

void *f(void *args){
  for (int i = 0; i < 100000; i = i + 1)
    counter_add(&ctr, 1);

  return NULL;
}

int main(int argc, char *argv[]){
  srand(time(NULL));
  ctr = counter_init(0);

  pthread_t fils[2];
  for (int i = 0; i < 2; i = i + 1)
    pthread_create(&fils[i], NULL, f, NULL);
  for (int i = 0; i < 2; i = i + 1)
    pthread_join(fils[i], NULL);

  printf("Valeur du compteur : %d\n", counter_value(ctr));
  return 0;
}
