Fix wrong mutex usage. (bug with throwing exception between lock and
unlock)