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: Tue, 03 Sep 2013 14:06:57 +0100
All sounds nice, except for the fact that the parameters are being changed "behind the scenes" via the binding system. So I think I may have to implement locking on every (explicitly implemented) get/set method. That was what I had been rather hoping to avoid, but it sounds from what people are saying as if that's what I may have to do...
On 3 Sep 2013, at 13:54, Robert Vojta wrote:
> On Tue, Sep 3, 2013 at 2:39 PM, Jonathan Taylor <email@hidden> wrote:
>
> The primary instance of the object (call it MyParameters) is bound to UI elements. Changes to the UI will change the values of its properties (int/bool/double). These changes will take place on the main thread.
>
> 1. Create MyParameters instance on some object on the main thread and call it mainParameters for example.
>
> 2. All values are UI related, so, fill them on the main thread. But lock your mainParameters object before. So, on the main thread do this ...
>
> @synchronized( myObjectHoldingMyParameters.mainParameters ) {
> myObjectHoldingMyParameters.mainParameters.X = X;
> ...
> }
>
> 3. When you do want a copy on any other thread, do this ...
>
> MyParamaters *paramsCopy;
> @synchronized( myObjectHoldingMyParameters.mainParameters ) {
> paramsCopy = [myObjectHoldingMyParameters.mainParameters copy];
> }
>
> ... and implement deep copy without locking. It's done via @synchronized.
>
>
_______________________________________________
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