[NSImageView setImage:theImage] Thread safe??
[NSImageView setImage:theImage] Thread safe??
- Subject: [NSImageView setImage:theImage] Thread safe??
- From: Trygve Inda <email@hidden>
- Date: Wed, 01 Jul 2009 19:47:13 +0000
- Thread-topic: [NSImageView setImage:theImage] Thread safe??
The docs at:
http://developer.apple.com/documentation/Cocoa/Conceptual/Multithreading/Thr
eadSafetySummary/ThreadSafetySummary.html
State:
The NSView class is generally thread-safe, with a few exceptions. You should
create, destroy, resize, move, and perform other operations on NSView
objects only from the main thread of an application. Drawing from secondary
threads is thread-safe as long as you bracket drawing calls with calls to
lockFocusIfCanDraw and unlockFocus.
If a secondary thread of an application wants to cause portions of the view
to be redrawn on the main thread, it must not do so using methods like
display, setNeedsDisplay:, setNeedsDisplayInRect:, or setViewsNeedDisplay:.
Instead, it should send a message to the main thread or call those methods
using the performSelectorOnMainThread: method instead.
So is this legal in a secondary thread?
NSImage* theImage = [[NSImage alloc] initWithContentsOfFile:someImagePath];
[imageView setImage:theImage];
[theImage release];
Note that imageView in an NSImageView in a window and both the window and
the NSImageView were created on the main thread. The secondary thread is
only creating an NSImage and attaching it to the NSImageView.
Safe?
Thanks,
Trygve
_______________________________________________
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