Compiler Optimization: Programmers are really dumb, and there are some things programmers can't control anyway. Optimation is when a compiler does not compile the program you actually type in but compiles a similar version that should do the same thing your does except run a bit faster. for (int j = 0; j < 100; j++) { printf ("%d\n",j); i = 17; } printf ("%d\n",i); This program prints the numbers from 0 to 99 and then prints 17. But there's no need for the i=17 to fire 100 times. So, an optimizing compiler will remove that line from the loop, so it only runs once. int i = 17; while (i < 20) { printf ("Hi\n"); } printf ("I\'m done!"); A good optimizing compiler will not even generate code for I'm done, because it's never going to get there. On the classic gcc compiler, there are 4 levels of optimization O1, O2, O3, and O4. I don't use O4 because O4 does not guarantee that the program will give the correct answer. I use O3 because it's the fastest optimization that guarantees the right answer. Evidently, that guarantee does not extend to threads. if (x=NULL) { ... } -Wall this would probably flag as a warning. Threads run as part of the same process. They use the same memory. Each thread has its own stack, including its own local variables, and each has its own program counter, so different threads can be running different sections of the same program, but they have to run the same program, and they share the same global memory, so global variables can be used to pass information between the threads. This is an example of "shared memory." It's used in threads all the time. Shared memory is also used in larger (expensive) parallel machines.