I think the acquire has to be inside the following if. Right now, if the code doesn't enter the if, the lock is held and never released.