(mostly) thread safe in C++