java-like synchronized blocks in c++