Yunding Li
Tianhang Zhang
Cunyang Shui
Yunding Li
Tianhang Zhang
Class
without
Instance?
SoccerPlayer
public :
static Instance* getInstance()
private:
static SoccerPlayer* _instance
Ronaldo
public :
static Instance* getInstance()
protect:
Ronaldo() {SoccerPlayer* me = Ronaldo}
Zidane
public :
static Instance* getInstance()
protect:
Zidane() {SoccerPlayer* me = Zidane}
Maldini
public :
static Instance* getInstance()
protect:
Maldini() {SoccerPlayer* me = Maldini}
Simple Implementation:
Ask for instance of
subclass
Check Registry
Exsit: assign instance
to pointer and return
Not exist: return 0
Registry Implementation:
Registry Implementation:
Cunyang Shui
condition
two thread may call the constructor at
the same time -> Singleton Broken
condition
MUTEX
If two thread pass the condition at the
same time -> Singleton Broken
MUTEX
condition
MUTEX
condition
Low efficiency,
We don’t need to wait for the
mutex after first time
condition
MUTEX
condition
create
character
Protect thread
High efficiency
© Copyright 2026 Paperzz