• 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
[Solved] image processing thread lock up
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Solved] image processing thread lock up


  • Subject: [Solved] image processing thread lock up
  • From: John Pannell <email@hidden>
  • Date: Sun, 24 Oct 2004 16:30:07 -0600

Hi list-

Just writing for the archives... I had a problem with an app performing some image processing (thumbnailing) in threads. It took some time searching the archives to solve, and the posts leading to the solution were not obvious enough for my limited skills, thus this detailed report.

Symptom: multi-threaded image processing application would hang with spinning rainbow cursor at random intervals. Anecdotal reports seemed like more powerful machines (dual G5's vs. my G3 iBook) had more severe problems. Might process 2000 images before hang, might just get through 10, which was really embarrassing :-)

Notable app features: application creates thumbnails of images in separate thread(s).

CHUD says: Spin Control reveals many semaphore_wait conditions. Thread viewer shows the thumbnail generating threads are stuck in a deadlock during the spinning rainbow cursor. One thread would be stuck with "NSAppKitImgLock" and "GrowCacheWindow", while the others were stuck in [NSImage lockFocus].

Code snippet: In the processing thread, the relevant code read...

[thumbImage lockFocus];
[[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationLow];
[theImage setSize:[at transformSize:[theImage size]]];
[theImage compositeToPoint:NSMakePoint((96-[theImage size].width)/2 , (96-[theImage size].height)/2) operation:NSCompositeCopy];
[thumbImage unlockFocus]; // this image is now an NSCachedImageRep

Simply rendering a large image into the thumbnail's context at the new size.

Problem: WIthout the threading, things would be fine. However, in a threaded environment, one must make sure that the images being rendered (in this case, thumbImage) are cached separately. The use of a shared cache (which is the default behavior for an NSImage) will cause a deadlock when the app kit must resize the window containing the shared cache - the currently drawing thread has a lock when the app kit asks for a lock in order to resize, but the drawing thread cannot release its lock until it can draw, which cannot happen until the resize, etc., etc. (This is my understanding of it anyway - no guarantees I'm correct on my reasoning)

Solution: In a multi-threaded environment, make sure the images being rendered are being cached separately, a la...

[thumbImage setCachedSeparately:

Hope this helps someone, somewhere, at some point in time :-) It did resolve the hang issue.

John

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
  • Prev by Date: Critique of Java GUI vs Cocoa
  • Next by Date: Re: NSAffineTransform
  • Previous by thread: Re: Critique of Java GUI vs Cocoa
  • Next by thread: Date strings in NSTextFields
  • Index(es):
    • Date
    • Thread