Use scoped locks instead of CRITICAL_BLOCK