Can I access (without locking) an std::map entry while another thread inserts/erases entrys?
example pseudo C++:
typedef struct {
int value;
in
No no no no no!
map::erase
modifies the links between the map entries and that messes with the search algorithm used in map::at
. You can use the elements during an erase, but you can not execute the searching algorithm itself!
I've created an illustration program. On my machine this program sometimes print OK, sometimes throws a map exception - that means that the search is gone wrong. Increasing the number of reading threads make the exception appear more often.
#include
#include
#include