Re: Threadsafe copy of objective c object
Re: Threadsafe copy of objective c object
- Subject: Re: Threadsafe copy of objective c object
- From: Marcel Weiher <email@hidden>
- Date: Wed, 04 Sep 2013 17:46:03 +0200
On Sep 4, 2013, at 10:56 , Jonathan Taylor <email@hidden> wrote:
> On 3 Sep 2013, at 19:49, Marcel Weiher <email@hidden> wrote:
>> Unless there is some dire reason not to do this, I would make a copy on the main thread every time the UI changes, and stash that copy somewhere the worker thread can access it easily.
>
> That's a really good plan, I realised that last night. I had been stuck thinking about kind of the opposite approach (make a copy on each invocation of the processing algorithm), but this makes a lot of sense. How does this sound:
>
> When the UI leads to changes in the (mutable) primary object I'll make a copy stored in an immutable shadow object (from the main thread).
> Whenever the algorithm is invoked (from a secondary thread in response to receipt of a frame) I retain the immutable shadow object and pass this pointer to the algorithm.
Sounds pretty good to me. I’d probably stash it in an instance variable. In a sense, this is a variant of the immutability that Ian and Jens suggested: create a copy that you won’t mutate.
> From what Jens and others have said, it's my understanding that if the property for the (immutable) shadow object is designated atomic/retain then I wouldn't need a mutex to access it.
Yep.
Marcel
_______________________________________________
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