Why does the following double-checked-locking pattern remain subtly broken even though the lock is taken, and what fixes it?
private static Singleton _instance;
private static readonly object _lock = new();
public static Singleton Instance {
get {
if (_instance == null) { // fast path, no fence
lock (_lock) {
if (_instance == null)
_instance = new Singleton();
}
}
return _instance;
}
}