how'd you apply thread safe functionality to static functions of a struct
class SingleSome {
struct Static {
private static var instance: SingleSome?
//need barrier sync
static func getInstance(block: () -> SingleSome) -> SingleSome {
if instance == nil {
instance = block()
}
return instance!
}
static func remove() { //need barrier sync
instance = nil
}
}
}
reason a block was used as param as there could be inherited objects of SingleSome
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…