use defer for unlocking mutex