How does copy-on-write ensure the thread safety? When I was looking for how to implement copy-on-write in C++, I saw the implementation as below: