dispatch_once_t
must not be an instance variable.
The implementation of dispatch_once()
requires that the dispatch_once_t
is zero, and has never been non-zero. The previously-not-zero case would need additional memory barriers to work correctly, but dispatch_once()
omits those barriers for performance reasons.
Instance variables are initialized to zero, but their memory may have previously stored another value. This makes them unsafe for dispatch_once()
use.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…