Thread synchronization with Lock and RLock