On 6 Mar 2012, at 1:51 PM, Jan E. Schotsman wrote:

> Is it safe to access this array from multiple threads, using methods like 
> objectAtIndex and replaceObjectAtIndex?

You can access immutable Foundation objects across threads, but not mutable 
ones, which is what you're thinking of. Your threads _will_ attempt to alter 
the array simultaneously, or to access elements while others are doing 
insertions and deletions. Referring to the array through an atomic accessor 
doesn't help: Your problem isn't with assigning into the instance variable, 
it's with changes to the array itself.

There are strategies to deal with this. I can think of many, but I don't have 
time to lay them out, or even to determine which of them are half-baked. It's a 
solved problem, but the solutions are not pretty compared to the hope that 
immediate parallel access will just work.

> I have an array of progress values (number objects) for subprojects, from 
> which I calculate the overall progress.


Try keeping an array of whatever objects represent the subtasks, each of which 
would have an atomic accessor to its count. Then have your overall object poll 
them.

        — F


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to