// Just counting, but with no protection on the concurrent // additions. We need a big N for the effect to become apparent. // // Compile: gcc badcounter.c -o badcounter -lpthread // Run: ./badcounter #include #include #include #include #define P 4 #define N 20000000 // make sure that the compiler doesn't // optimise this into a register volatile int target; void *adderthread (void *arg) { int i; for (i=0; i