Fix a bug in locking where a single thread that requests a shared lock followed by an exclusive lock would deadlock