java-like synchronize blocks in c++