开发者

Does +(void)initialize do any thread locking?

Looking at the definition for "initialize":

+ (void)initialize

Discussion

The runtime sends initialize to each class in a program exactly one time just before the class, or any class that inherits from it, is sent its first message from within the program. (Thus the method may never be invoked if the class is not used.) The runtime sends the initialize message to classes in a thread-safe manner. Superclasses receive this message before their subclasses.

it is stated that initialize is sent in a "thread-safe manner". Under the covers, 开发者_JAVA技巧is the runtime creating a lock to make that call thread safe or is it inherently thread-safe just from the way the runtime works? If it does lock, does that mean if you implement +initialize the runtime creates a lock it would not otherwise have created?


I can't answer whether or not it locks, but regardless of whether or not you implement +initialize, it's still called. The default implementation may do something, but it's still called. So if the runtime does lock, then the lock is created regardless of whether or not the method is implemented by your subclass.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜