C++/ReaderWriterLock: Refactor the sample code