The assembled version of the above sample code contains these lines: ADD R3,R0,R1 ; R3=a+b LEA R4, c ; get address of global variable c STR R3, R4, #0 ; put result into global variable c LEA R0, LOCK_C AND R1,R1,#0 STR R1,R0,#0 an optimizing compiler, for reasons that only it knows, decides that doing BLOCK stores and writes to memory are better for performance, so it collects all the memory loads and all of the memory stores into localized blocks as follows: LEA R0, LOCK_C LEA R4, c ; get address of global variable c AND R1,R1,#0 ADD R3,R0,R1 ; R3=a+b STR R1,R0,#0 STR R3,R4, #0 ; put result into global variable c What is wrong with this "optimized" version of the code IF you were actually running it in a multi-threaded environment even if it does all the same things as the original code in terms of modifying memory as needed when it ALL runs? Be specific in your answer.
The assembled version of the above sample code contains these lines:
ADD R3,R0,R1 ; R3=a+b
LEA R4, c ; get address of global variable c
STR R3, R4, #0 ; put result into global variable c
LEA R0, LOCK_C
AND R1,R1,#0
STR R1,R0,#0
an optimizing compiler, for reasons that only it knows, decides that doing BLOCK
stores and writes to memory are better for performance, so it collects all the
memory loads and all of the memory stores into localized blocks as follows:
LEA R0, LOCK_C
LEA R4, c ; get address of global variable c
AND R1,R1,#0
ADD R3,R0,R1 ; R3=a+b
STR R1,R0,#0
STR R3,R4, #0 ; put result into global variable c
What is wrong with this "optimized" version of the code IF you were actually
running it in a multi-threaded environment even if it does all the same things as the
original code in terms of modifying memory as needed when it ALL runs? Be
specific in your answer.
Step by step
Solved in 2 steps