Singleton 模式与双检测锁定(DCL)

Aiur · Zellux at 
看 OOP 教材时,书里提到了一个双检测锁定(Double-Checked Lock, DCL)的问题,但是没有更多介绍,只是说这是一个和底层内存机制有关的漏洞。查阅了下相关资料,对这个问题大致有了点了解。从头开始说吧。在多线程的情况下 Singleton 模式会遇到不少问题,一个简单的例子 class Singleton { private static Singleton instance = null; public static Singleton instance() { if (instance == null) { instance……