Is enumerateUsingBlock: thread safe? I mean, can I mutate an NSMutableArray while enumerating it using enumerateUsingBlock on another thread?
How about enumerateObjectsWithOptions:usingBlock: when using NSEnumerationConcurrent option?
Is enumerateUsingBlock: thread safe? I mean, can I mutate an NSMutableArray while enumerating it using enumerateUsingBlock on another thread?
How about enumerateObjectsWithOptions:usingBlock: when using NSEnumerationConcurrent option?
No. NSMutableArray
is never intrinsically thread safe. All enumeration assumes the collection remains unmodified, including NSEnumerationConcurrent
. If you modify the collection during an enumeration, even from the same thread, an exception will be thrown.