Make sure to take the lock before entering the waitcond