When not explicitly needed, switch to lock_guard.