Re: Threadsafe copy of objective c object
Re: Threadsafe copy of objective c object
- Subject: Re: Threadsafe copy of objective c object
- From: Jonathan Taylor <email@hidden>
- Date: Thu, 05 Sep 2013 11:52:20 +0100
On 4 Sep 2013, at 16:46, Marcel Weiher 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.
OK, thanks everyone for your input on this one. I've got something I'm fairly happy with now, which is working according to plan. I was a bit surprised at how much "glue" I ended up having to put together to make it work though. Maybe that's just the nature of the thing, but if anybody was interested enough to critique the code that I've come up with (on or off list) then I'd be very grateful to hear any comments.
https://docs.google.com/file/d/0Bye8FKbpg3dYa1R2Z1hPWERmcjQ/edit
Cheers
Jonny.
_______________________________________________
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