// ga is a global variableint func_a() { int a = ga; return a>2 ? a-2 : 2-a;}int func_b() { return ga>2 ? ga-2 : 2-ga;}
// ga is a global variableint func_a() { int a = ga; return a>2 ? a-2 : 2-a;}int func_b() { return ga>2 ? ga-2 : 2-ga;}
Are these two code snippets functionally identical in a multi-threaded or real-time operating system (RTOS) environment? Specifically, is the first code guaranteed to safely read the global variable
ga
ga
only once, ensuring consistent behavior even if
ga
ga
changes? This is not about data protection mechanisms like locks, but rather compiler behavior regarding register assignment and variable reading. @Middleware & OS