Open NicklasWallgren opened 2 months ago
There is a risk that initialized is cached between threads, leading to multiple initializations.
initialized
Explaination;
get
firstTime
delegate
Fix; Make initialized and delegate volatile to ensure visibility across threads.
volatile
There is a risk that
initialized
is cached between threads, leading to multiple initializations.Explaination;
get
and enters thefirstTime
method.firstTime
completes, Thread 2 callsget
.initialized
might not be updated yet (due to thread interleaving), Thread 2 might also enter thefirstTime
method.delegate
andinitialized
, leading to multiple initializations.Fix; Make
initialized
anddelegate
volatile
to ensure visibility across threads.