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.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter6: Modularity Using Functions
Section6.2: Returning A Single Value
Problem 1E
icon
Related questions
Topic Video
Question

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.

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Instruction Format
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr