#include /* interfere.c */ #include #include /* for strtol */ #include /* for strerror */ static volatile long int counter = 0; static long int max; void * count(void * arg) { /* main function for thread */ long int i, reg, * mycounter = arg; for(i = 0; i < max; i++) { reg = *mycounter; reg = reg + 1; *mycounter = reg; } return NULL; } int main (int argc, char * argv[]) { int error; pthread_t tid; max = strtol(argv[1], NULL, 10); if (error = pthread_create(&tid, NULL, count, &counter)) fprintf(stderr, "Failed to spawn: %s\n", strerror(error)); else { count( &counter ); if (error = pthread_join(tid, NULL)) fprintf(stderr, "Failed to join: %s\n", strerror(error)); else fprintf(stderr, "The final count was %ld\n", counter); } return 0; }