/*
 * @date   03.11.2008
 * @author Sebastian Hack
 *
 * Copyright (C) 2008 Saarland University
 * Released under the GPL
 */

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

static volatile int val;

static void *update(void *dummy) {
	(void) dummy;
	for (;;) 
		val = val + 1;
	return NULL;
}

static void do_stuff(int n) {
	int begin, end, sum, i;

	begin = val;

	/* very long computation */
	sum = 0;
	for (i = 0; i < n; i++)
		sum += i;

	end = val;

	printf("%d %d %d\n", sum, begin, end);
}

int main(int argc, const char *argv[]) {
	if (argc > 1) {
		pthread_t updater;
		pthread_create(&updater, NULL, update, NULL);
		do_stuff(atoi(argv[1]));
	}
	return 0;
}


