I have two threads:
Comments are saying the right thing. I will combine them with your statement:
If they are executed in parallel, one thread (when it starts its work) may face a partially modified object (the other thread is working on it). The result of action on a partially modified object is undefined. This is the source of the problem.
If you synchronize access to your object with say
mutex everything will work fine. Containers do not have built in synchronization because this would significantly slow down their work while this is needed only sometimes.