Reputation: 1
In objective C, is it thread safe to add an object to an array (all processing/mutating/enumeration of this array occurs on its own single thread), whilst the object itself could potentially be mutated on a different thread?
When adding an object to an array, am I simply passing in a memory reference, and changes to the actual object will not cause issues at this point? Or will mutating that object on a different thread at the same time as adding it to an array result in a crash?
Thanks
Upvotes: 0
Views: 115
Reputation: 501
Yes, it is thread safe.
Upvotes: -1
Reputation: 52548
Yes, it's safe. The array only cares about storing a reference to the object. Any changes to the object itself are totally invisible to the array. Of course if one thread reads myObject = myArray [i] then that thread must be aware that the contents of the object could change at any time.
Upvotes: 2