Re: returning from within @synchronized results in warnings
Re: returning from within @synchronized results in warnings
- Subject: Re: returning from within @synchronized results in warnings
- From: Ken Thomases <email@hidden>
- Date: Wed, 12 Aug 2009 09:27:56 -0500
On Aug 12, 2009, at 9:04 AM, Jeremy Pereira wrote:
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).
Not all properties are Objective-C object pointers or other data types
which can be accessed atomically at the instruction level. For
example, an NSRect property.
But the larger point is that there are reasons to synchronize on self
which go beyond the property being considered at the moment. Cem may
have been synchronizing on self for one of those reasons, and the
suggestion that a synthesized accessor would be equivalent was
potentially dangerously misleading.
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