Take the 2-minute tour ×  After posting my solution to my own
problem regarding memory issues, nusi suggested that my solution
lacks locking.  The following pseudo code vaguely represents my
solution in a very simple way.  std::map<int, MyType1> myMap;
void firstFunctionRunFromThread1()     MyType1 mt1;     mt1.Test
= "Test 1";     myMap[0] = mt1;  void
onlyFunctionRunFromThread2()     MyType1 &mt1 = myMap[0];
std::cout << mt1.Test << endl; // Prints "Test 1"     mt1.Test =
"Test 2";  void secondFunctionFromThread1()     MyType1 mt1 =
myMap[0];     std::cout << mt1.Test << endl; // Prints "Test 2"
I'm not sure at all how to go about implementing locking, and
I'm not even sure why I should do it (note the actual solution
is much more complex). Could someone please explain how and why
I should implement locking in this scenario?  share|improve this
question add comment  6 Answers  up vote 1 down vote accepted
In general, threads might be running on different CPUs/cores,
with different memory caches. They