On Jan 29, 2015, at 10:54 PM, Quincey Morris 
<quinceymor...@rivergatesoftware.com> wrote:

> On Jan 29, 2015, at 19:47 , Greg Parker <gpar...@apple.com> wrote:
>> 
>> `atomic` makes a big difference for a strong or weak property of object type 
>> because objects have retain counts.
> 
> Er, I feel stupid but I don’t understand. How do the retain counts affect 
> this? On the one hand, properties are not the only place where retain counts 
> are manipulated, and on the other hand, don’t retain count changes have to be 
> atomic anyway?

The getter for a strong property needs to return either nil or a pointer that's 
valid.  It can't return a pointer to an object that's been deallocated.  If the 
thread on which the getter has been called is racing a thread which is setting 
the property to a different pointer (and thus releasing a reference), the 
getter has to do the equivalent of retain+autorelease atomically with respect 
to the setter doing a (retain new value)+(replace pointer)+(release old value).

For a weak property, the property has to be registered with the runtime as the 
location for a particular weak object and, when set to a new value, 
unregistered.  The runtime needs to know the location of all weak pointers to 
each object so that when the object is (about to be) deallocated, it can nil 
out those pointers. Basically, the racing threads are calling objc_loadWeak() 
vs. objc_storeWeak().  The former has, again, the semantics of a 
retain+autorelease so that the reference is valid for the caller's context (if 
it's not nil).

Regards,
Ken


_______________________________________________

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

Reply via email to