• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Threadsafe copy of objective c object
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Threadsafe copy of objective c object
      • From: Jonathan Taylor <email@hidden>
References: 
 >Threadsafe copy of objective c object (From: Jonathan Taylor <email@hidden>)
 >Re: Threadsafe copy of objective c object (From: Graham Cox <email@hidden>)
 >Re: Threadsafe copy of objective c object (From: Lasse Jansen <email@hidden>)
 >Re: Threadsafe copy of objective c object (From: Diederik Meijer | Ten Horses <email@hidden>)
 >Re: Threadsafe copy of objective c object (From: Jonathan Taylor <email@hidden>)

  • Prev by Date: Re: Threadsafe copy of objective c object
  • Next by Date: Re: Threadsafe copy of objective c object
  • Previous by thread: Re: Threadsafe copy of objective c object
  • Next by thread: Re: Threadsafe copy of objective c object
  • Index(es):
    • Date
    • Thread