This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Right way to ensure assignment order of global variables under optimization

I've got a case where I set two global variables in a function.  Then, another context reads them and assumes that the order they are assigned holds.  However, with optimization level 2 on, my variables are getting set out of order.  I can see why the compiler might say this is OK since maybe it doesn't worry about the other context.  So, what's the right way to handle this case?  I've installed HWI_disable() and HWI_enable() to create a critical section around the two assignments.  Although it works, I'm wondering if there's a better approach.