Re: Accessing array in thread safe way
Re: Accessing array in thread safe way
- Subject: Re: Accessing array in thread safe way
- From: Nick Zitzmann <email@hidden>
- Date: Tue, 06 Mar 2012 17:15:34 -0700
On Mar 6, 2012, at 12:51 PM, Jan E. Schotsman wrote:
> Hello,
>
> I have an array of progress values (number objects) for subprojects, from which I calculate the overall progress .
> The array is an atomic property of the project class.
>
> Is it safe to access this array from multiple threads, using methods like objectAtIndex and replaceObjectAtIndex?
Only if the array is immutable. You have to manually lock and unlock any mutable collection provided by Foundation (except for NSCache) before reading from or writing to the collection, because NSCache is the only collection object that is thread-safe.
And atomic properties lock access to the instance variable, but they don't lock the contents of the instance variable, which is why it's not always the best idea to make mutable objects available as properties. I could probably be a better help if I knew more about what you were trying to accomplish.
Nick Zitzmann
<http://www.chronosnet.com/>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden