use a more safe way to release lock