fixing deadlock when taking wirte lock inside a read lock