Re: How to implement readonly property
Re: How to implement readonly property
- Subject: Re: How to implement readonly property
- From: Jeremy Pereira <email@hidden>
- Date: Fri, 07 Dec 2012 15:03:06 +0000
On 12 Nov 2012, at 20:45, Greg Parker <email@hidden> wrote:
>
>
> There is something special about statically-allocated memory. Statically-allocated memory has always been zero for the life of the process. Dynamically-allocated memory may have been non-zero at some point in the past (i.e. if it was previously part of a now-freed allocation).
>
> The problem is your condition #2. If the memory was previously non-zero and you set it to zero, you need appropriate memory barriers on some architectures to prevent a race where the caller of dispatch_once() sees the old non-zero value. Neither dispatch_once() nor the malloc system nor the Objective-C runtime promise to provide the correct barriers.
>
> In some cases you might be able to add an appropriate memory barrier to your -init... method, assuming that no calls to dispatch_once() occur before then.
>
> In practice this is a difficult race to hit, but it's not impossible.
>
Sorry, I'm a bit late to the party here but I've just read this and I don't understand it.
If this race condition really exists, you couldn't assume that *any* instance variables of a newly initialised object have been zeroed out.
What am I missing?
_______________________________________________
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