Non è che magari chiami quella funzione da due thread diversi?
Amaro C++, il gusto pieno dell'undefined behavior.
Regole del Forum