I am facing some strange issue in the code below which is compiled in linux,
The below piece of code iterates a map "ObjectsMap" from Begin and inside the iteration loop, I am trying to change the value of a different key in the same map "ObjectsMap".
map<int, ObjectA>::iterator outerItr = reDt->ObjectsMap->begin();
for (; outerItr!= reDt->ObjectsMap->end(); outerItr++)
{
int parentid = outerItr->second.parentID;
map<int, ObjectA>::iterator innerItr = reDt->ObjectsMap->find(parentid);
if (innerItr != reDt->ObjectsMap->end())
{
innerItr->second.selfTime = innerItr->second.selfTime + outerItr->second.execTime;
}
}
While this code executes, I am getting incorrect/unexpected value in the selfTime. But if I add some log inside the if() block then strangely the value is correct. If the log is removed then again I get incorrect value in selfTime.
What is that strange thing here.? Is it because of data race behavior?
Update 1:
selfTime value that I get is not Junk. But it is incorrect value, the value is higher than expected - I mean "outerItr->second.execTime" of some more incorrect keys also gets added to "innerItr->second.selfTime"