• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: [NSImageView setImage:theImage] Thread safe??
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: [NSImageView setImage:theImage] Thread safe??
      • From: Trygve Inda <email@hidden>
References: 
 >[NSImageView setImage:theImage] Thread safe?? (From: Trygve Inda <email@hidden>)

  • Prev by Date: Re: libSystem.B.dylib
  • Next by Date: Re: Only allowing a file to be opened by one app
  • Previous by thread: [NSImageView setImage:theImage] Thread safe??
  • Next by thread: Re: [NSImageView setImage:theImage] Thread safe??
  • Index(es):
    • Date
    • Thread