Re: Threadsafe copy of objective c object
Re: Threadsafe copy of objective c object
- Subject: Re: Threadsafe copy of objective c object
- From: Robert Vojta <email@hidden>
- Date: Tue, 03 Sep 2013 14:54:36 +0200
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