Re: Accessing array in thread safe way
Re: Accessing array in thread safe way
- Subject: Re: Accessing array in thread safe way
- From: Quincey Morris <email@hidden>
- Date: Fri, 09 Mar 2012 00:51:54 -0800
On Mar 9, 2012, at 00:30 , CoGe - Tamas Nagy wrote:
> Thanks Quiencey to pointing this out, however, what you suggest instead of the current implementation? What I use for this class is putting and/or update objects into it from different threads, then access it from an other (reader) thread (via objectAtIndex: and by enumarating).
It depends on how often the array gets updated and how big it is. One simple approach is to serialize all access to the array through the main thread (e.g. via 'performSelectorOnMainThread'), but you'd have to enumerate a (serially-retrieved) copy of the array each time.
The most flexible solution might be to use NSOperationQueue (or GCD) to set up some kind of producer/consumer model. But it still depends on the details of what you're trying to do.
_______________________________________________
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