I have a global var std::unordered_map < std::string,int > themap .
the thread1 do the following :
Time1 :
string s = "user1" ;
themap[s] = 100 ;
Time2 :
string s = "user2" ;
themap[s] = 101 ;
the thread2 do the following :
Time2:
string s = "user1" ;
auto got = themap.find( s ) ;
Time1 happened before Time2 , suppose that in thread2 , got != themap.end() will be correct and got->second = 100 !!! What bother me is that , if in the very moment Time2 , thread1 is doing themap["user2"] = 101 , which will modify themap's memory structure , thread2 themap.find doing find at the exact same time thread1 modify themap's memory contents , if without lock , still I get got != themap.end() ? and got->second = 100 ?
themap["user2"] = 101 and got = themap.find( s )
doing at the exact same time will cause got->second not to 100 ?
Aucun commentaire:
Enregistrer un commentaire