Design patterns·Making things
the code checks whether it is initialised, takes a lock, and checks again — and the second check is not redundant.
Double-checked locking
Also calleddouble checked locking, DCL
The idiom for lazily initialising a shared field without paying for a lock on every read: test, lock, test again, initialise. It is famous for having been subtly broken for years in several languages because without the right memory-model guarantee another thread can observe a partially constructed object. It is worth knowing as an interview answer about memory visibility, and worth avoiding in real code in favour of whatever your language's lazy holder is.