• 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: returning from within @synchronized results in warnings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: returning from within @synchronized results in warnings


  • Subject: Re: returning from within @synchronized results in warnings
  • From: Jeremy Pereira <email@hidden>
  • Date: Wed, 12 Aug 2009 15:04:08 +0100


On 12 Aug 2009, at 13:59, Ken Thomases wrote:


No, declared and synthesized properties will not synchronize on self. If declared (or allowed to default to) atomic, then they use some techniques to make sure that no thread calling the getter will get an inconsistent value -- they will either see the value as it was before a given setter or as it is after, but never some in- between frankenstein value -- but atomic properties don't guarantee any consistency of that property with respect to the rest of the object's state. Of course, merely synchronizing on self doesn't guarantee that either, but if the rest of the implementation also uses synchronization properly, it can achieve that.

I think the above is only partially correct. Maybe I'm wrong, but since getting an Objective-C object only involves putting a pointer on the stack or in a register it is by definition atomic (unless it's possible to interrupt a processor half way through reading an address from memory).


However, declaring a property atomic (or more correctly, not declaring it nonatomic) and then synthesizing ensures that, in a threaded environment, the object returned will not have been deallocated by some other thread before the current thread has a chance to do something with it. And that's pretty much all it does in the getter.

In fact, the docs show that what happens is very similar to Cem's code except it uses some internalper property lock that we don't need to care about.

http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/ObjectiveC/Articles/ocProperties.html#/ /apple_ref/doc/uid/TP30001163-CH17-SW14



Regards, Ken

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Xcode-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: returning from within @synchronized results in warnings
      • From: Ken Thomases <email@hidden>
References: 
 >returning from within @synchronized results in warnings (From: "Karan, Cem (Civ, ARL/CISD)" <email@hidden>)
 >Re: returning from within @synchronized results in warnings (From: Paul Summermatter <email@hidden>)
 >Re: returning from within @synchronized results in warnings (From: Ken Thomases <email@hidden>)

  • Prev by Date: Re: returning from within @synchronized results in warnings
  • Next by Date: Re: returning from within @synchronized results in warnings
  • Previous by thread: Re: returning from within @synchronized results in warnings
  • Next by thread: Re: returning from within @synchronized results in warnings
  • Index(es):
    • Date
    • Thread