单例模式没有unlock,并发会造成死锁
xuxinx opened this issue · 1 comments
xuxinx commented
func GetInstance() *Singleton {
if singletonInst == nil {
// 多个线程进入这里会造成死锁
singletonInstLock.Lock()
if singletonInst == nil {
singletonInst = &Singleton{}
}
// 应该在此处UnLock
}
return singletonInst
}
senghoo commented
@xpzouying 修复了此问题