Hi, Basically you are trying to protect the values of an object while you are copying.
If this is the case, then wherever you access these properties you will be need to use a lock based on the object you are copying. In order to do this, you need to lock the whole object whenever you are accessing the values, one way of doing this is to do something like this: SafeObj* myCurrentObject; //Assume set to object you wish to copy. SafeObj* myNewObject; //** //** Read Values //** myNewObject = [[SafeObj alloc] initWithObject: myCurrentObject]; Then in initWithObject, do this: - (id) initWithObject:(SafeObj*) theObject; { self = [self init]; if (self == nil) return nil; @sychronized(theObject) { self.pVal1 = theObject.pVal1; self.pVal2 = [theObject.pVal2 copy]; self.pVal3 = [theObject.pVal2 mutableCopy]; } return self; } Of course, in the rest of the code that accesses pValX, you'd need to add @synchronized around getting and setting them. The properties obviously need to be protected as a set, so to read them, create a new local object using initWithObject to copy the values. To write to a set, you need to add another method: -(void) setValuesFromObject::(SafeObj*) theObject; { @sychronized(self) { self.pVal1 = theObject.pVal1; self.pVal2 = [theObject.pVal2 copy]; self.pVal3 = [theObject.pVal2 mutableCopy]; } } So, to increment pVal1, you'd do this: SafeObj* myCurrentObject; //Assume set to object you wish to copy. SafeObj* myNewObject; //** //** Read Values //** myNewObject = [[SafeObj alloc] initWithObject: myCurrentObject]; myNewObject.pVal1++; [self setValuesFromObject: myNewObject]; Hope this helps Dave On 3 Sep 2013, at 11:52, Jonathan Taylor <jonathan.tay...@glasgow.ac.uk> wrote: > This feels like it should be a very basic question, but it's not one I've > managed to find an answer to - can somebody here advise? > > I have an objective c object which contains a number of properties that serve > as parameters for an algorithm. They are bound to UI elements. I would like > to take a snapshot copy of the object that will be used for one whole run of > the algorithm (rather than risk parameters changing halfway through the run). > i.e. I just want to do [myObject copy]. > > The complication is in ensuring this is threadsafe: ideally I would like to > make the copy on a thread other than the main thread. My understanding is > that properties themselves, even when designated atomic, are in some way not > fully threadsafe, although I haven't found a clear explanation of exactly > what makes them unsafe. I don't know if the 'copy' method is threadsafe or > not, I am inclined to suspect not. > > Is there any way, then, that I can take a copy in a threadsafe manner? If > necessary I can do the copy on the main thread, but I would prefer not to > have to do that for timing reasons. Any suggestions? > > Cheers > Jonny. > _______________________________________________ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > 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: > https://lists.apple.com/mailman/options/cocoa-dev/dave%40looktowindward.com > > This email sent to d...@looktowindward.com _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com