I have two thread, thread 1 may add or delete to a map
//t1
std::map<int, int> my_map;
my_map[9] = 9;
And thread2 check if a certain key exists in the map,
//t2
void check_and_act() {
if(my_map.find(9)==my_map.end()) {
//do something
}
}
check_and_act
in t2
will be called repeatedly, so I do not care if operation in t1
is performed earlier or later than check done in t2
, is there going to be any undefined behavoir in this case?