clean c++11 code: using lock, instead swap and copy ptr