Re: @synchronized([someObject class])
Re: @synchronized([someObject class])
- Subject: Re: @synchronized([someObject class])
- From: Greg Parker <email@hidden>
- Date: Tue, 19 Jun 2007 12:10:14 -0700
Ruotger Skupin wrote:
is it possible to do @synchronized([someClass class])?
Yes.
- (NSDictionary*) elementTypes
{
static NSMutableDictionary *result;
@syncronized([self class])
{
if (nil == result)
{
// same as above
}
}
return result;
}
...but this isn't thread-safe.
The problem is that `[self class]` might not always be the same class.
If the class has subclasses then different instances would lock on
different class objects. (Beware that other systems like Key-Value
Observing may create subclasses without your knowledge, even if you
don't have any subclasses in your code.)
A better way to write that is to use a specifically-named class,
regardless of the receiver's actual class:
@synchronized([MyClass class])
--
Greg Parker email@hidden Runtime Wrangler
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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