Suppose I have my own non-inline functions LockMutex and UnlockMutex, which are using some proper mutex - such as boost - inside. How will the compiler know not to reorder o
If the compiler can't guarantee that the function calls won't have side effects that will modify the variables between the calls, it can't move the code. If the variable is a local variable and you've never taken a reference or created a pointer to it, the compiler might assume it's safe to move; I don't know.