#include<stdio.h>
#include<stdlib.h>
#include<pthread.h>


volatile int a = 0;
volatile int b = 0;
void * reader(void *junk) {
     while(1) {
	  int tb = b;
	  int ta = a;
	  if (ta < tb) {
	       fprintf(stderr, "%d\n", ta - tb);
	  }
     }
     return NULL;
}

void * writer(void *junk) {
     int i;
     while (1) {
	  a++;
	  b++;
     }
     return NULL;
}

int main (int arcgv, char *argv[]) {
     pthread_t threads[2];
     int i;
     pthread_create(&threads[0], NULL, reader, NULL);
     pthread_create(&threads[1], NULL, writer, NULL);
     pthread_join(threads[1], NULL);

     fprintf(stderr, "%d %d\n",a , b);
     return 0;
}
