Re: [NSImageView setImage:theImage] Thread safe??
Re: [NSImageView setImage:theImage] Thread safe??
- Subject: Re: [NSImageView setImage:theImage] Thread safe??
- From: Michael Ash <email@hidden>
- Date: Wed, 1 Jul 2009 18:52:32 -0400
2009/7/1 Trygve Inda <email@hidden>:
> So is this legal in a secondary thread?
>
> NSImage* theImage = [[NSImage alloc] initWithContentsOfFile:someImagePath];
> [imageView setImage:theImage];
> [theImage release];
No.
There's a very simple rule to follow when examining thread safety. The
default state of any code is not to be thread safe. Thus, look at the
documentation: is the method in question *explicitly* documented to be
thread safe? If not, then it is not thread safe. A lack of
documentation means it's unsafe, not that it's safe.
That NSView is mostly thread safe confers nothing on subclasses of
NSView. They're talking only about NSView's methods. Any new methods
added by subclasses aren't covered.
Furthermore, beware of weasel words like "with a few exceptions",
especially when followed with this:
"You should create, destroy, resize, move, and perform other
operations on NSView objects only from the main thread of an
application."
I have no idea how this squares with "generally thread-safe", but when
in doubt, assume it's not.
Since -[NSImage setImage:] is nowhere documented to be thread safe
that I can see, you must assume that it's not.
Mike
_______________________________________________
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