I recently stumbled upon this Wikipedia article. From my experience with multi-threading I am aware of the multitude of issues caused by the program being able to switch threads
How do you prevent the possibility out of execution functions occurring and blowing up in your face?
You don't - the compiler can only change the order of execution when doing so doesn't alter the end result.