Tutorial :Application hanging in __semwait_signal ()



Question:

I have a user of my application that sometimes when they run the application it gets stuck at the following point ...

0x92542782 in __semwait_signal ()  (gdb) where  #0  0x92542782 in __semwait_signal ()  #1  0x9254243e in _pthread_cond_wait ()  #2  0x925440d8 in pthread_cond_wait$UNIX2003 ()  #3  0x95232670 in fe_fragment_render_quad ()  #4  0x9522f07f in fe_sw_quad ()  #5  0x9522edf9 in fe_context_quad ()  #6  0x95227915 in fe_tree_render_apply_1 ()  #7  0x9522244f in fe_tree_render_apply ()  #8  0x95220c9b in fe_tree_render_ ()  #9  0x9522443c in fe_tree_render_texture ()  #10 0x95224295 in texture_retain ()  #11 0x95223d5d in fe_texture_new ()  #12 0x95222a62 in fe_tree_create_texture ()  #13 0x95222159 in fe_tree_render_apply ()  #14 0x95220c9b in fe_tree_render_ ()  #15 0x9522443c in fe_tree_render_texture ()  #16 0x95224295 in texture_retain ()  #17 0x95223d5d in fe_texture_new ()  #18 0x95222a62 in fe_tree_create_texture ()  #19 0x95222159 in fe_tree_render_apply ()  #20 0x95220c9b in fe_tree_render_ ()  #21 0x9522443c in fe_tree_render_texture ()  #22 0x95224295 in texture_retain ()  #23 0x95223d5d in fe_texture_new ()  #24 0x95222a62 in fe_tree_create_texture ()  #25 0x95222159 in fe_tree_render_apply ()  #26 0x95220c9b in fe_tree_render_ ()  #27 0x95220bef in fe_tree_render_ ()  #28 0x9522443c in fe_tree_render_texture ()  #29 0x95224295 in texture_retain ()  #30 0x95223d5d in fe_texture_new ()  #31 0x95222a62 in fe_tree_create_texture ()  #32 0x95222159 in fe_tree_render_apply ()  #33 0x95220c9b in fe_tree_render_ ()  #34 0x952201e2 in fe_tree_render_tree ()  #35 0x9520e72a in fe_tree_render_image ()  #36 0x9520dfea in fe_image_render_ ()  #37 0x9520dae7 in fe_image_get_bitmap ()  #38 0x9520d8b7 in -[CIContextImpl render:toBitmap:rowBytes:bounds:format:colorSpace:] ()  #39 0x918f29e8 in cgxcoreimage_instance_render ()  #40 0x918f2ae8 in cgxcoreimage_provider_create_data ()  #41 0x9841d601 in faultDataAcquireBytePointer ()  #42 0x9837f20f in CGAccessSessionGetBytePointer ()  #43 0x983db0e0 in img_decode_read ()  #44 0x983daf47 in img_colormatch_read ()  #45 0x983dad7c in img_alphamerge_read ()  #46 0x983b8ee9 in img_data_lock ()  #47 0x983b5ee6 in CGSImageDataLock ()  #48 0x92b16748 in ripc_AcquireImage ()  #49 0x92b143be in ripc_DrawImage ()  #50 0x983b5b60 in CGContextDrawImage ()  #51 0x990ed9c6 in CUIPenCG::DrawImage ()  #52 0x990f9e85 in CUIRenderer::DrawImage ()  #53 0x990eaa94 in CUIRenderer::Draw ()  #54 0x90d6059c in -[NSCoreUIImageRep draw] ()  #55 0x90d60481 in -[NSImageRep drawInRect:] ()  #56 0x90d602fd in __-[NSImageRep drawInRect:fromRect:operation:fraction:respectFlipped:hints:]_block_invoke_2 ()  #57 0x90d6025b in NSGraphicsContextPushContextWithFlippedMetadata_drawWithBlock_ ()  #58 0x90cb4673 in __-[NSImageRep drawInRect:fromRect:operation:fraction:respectFlipped:hints:]_block_invoke_1 ()  #59 0x90cb3b39 in -[NSImageRep drawInRect:fromRect:operation:fraction:respectFlipped:hints:] ()  #60 0x90caed89 in -[NSImage _drawMappingAlignmentRectToRect:withState:backgroundStyle:operation:fraction:flip:hints:] ()  #61 0x90d5f42e in -[NSButtonCell drawImage:withFrame:inView:] ()  #62 0x90d5e941 in -[NSButtonCell _configureAndDrawImageWithRect:cellFrame:controlView:] ()  #63 0x90d5cba8 in -[NSButtonCell drawInteriorWithFrame:inView:] ()  #64 0x90d5c1bd in -[NSButtonCell drawWithFrame:inView:] ()  #65 0x90d5489e in -[NSControl drawRect:] ()  #66 0x90d4cce1 in -[NSView _drawRect:clip:] ()  #67 0x90d4b97f in -[NSView _recursiveDisplayAllDirtyWithLockFocus:visRect:] ()  #68 0x90d4bcb4 in -[NSView _recursiveDisplayAllDirtyWithLockFocus:visRect:] ()  #69 0x90d4bcb4 in -[NSView _recursiveDisplayAllDirtyWithLockFocus:visRect:] ()  #70 0x90d730c2 in -[NSToolbarItemViewer _recursiveDisplayAllDirtyWithLockFocus:visRect:] ()  #71 0x90d4bcb4 in -[NSView _recursiveDisplayAllDirtyWithLockFocus:visRect:] ()  #72 0x90d4bcb4 in -[NSView _recursiveDisplayAllDirtyWithLockFocus:visRect:] ()  #73 0x90d4bcb4 in -[NSView _recursiveDisplayAllDirtyWithLockFocus:visRect:] ()  #74 0x90d49e9e in -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] ()  #75 0x90d49a13 in -[NSThemeFrame _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] ()  #76 0x90d46359 in -[NSView _displayRectIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:] ()  #77 0x90ca6f26 in -[NSView displayIfNeeded] ()  #78 0x90c70292 in -[NSWindow displayIfNeeded] ()  #79 0x90c6ed30 in -[NSWindow _reallyDoOrderWindow:relativeTo:findKey:forCounter:force:isModal:] ()  #80 0x90c6e892 in -[NSWindow orderWindow:relativeTo:] ()  #81 0x90c6c054 in -[NSWindow makeKeyAndOrderFront:] ()  #82 0x000151a2 in -[AppController applicationFinishedLaunching:] ()  #83 0x9208f253 in _nsnote_callback ()  #84 0x98facc29 in __CFXNotificationPost ()  #85 0x98fac65a in _CFXNotificationPostNotification ()  #86 0x92084120 in -[NSNotificationCenter postNotificationName:object:userInfo:] ()  #87 0x920914fd in -[NSNotificationCenter postNotificationName:object:] ()  #88 0x90ca78f2 in -[NSApplication _postDidFinishNotification] ()  #89 0x90ca7802 in -[NSApplication _sendFinishLaunchingNotification] ()  #90 0x90dfe565 in -[NSApplication(NSAppleEventHandling) _handleAEOpen:] ()  #91 0x90dfe185 in -[NSApplication(NSAppleEventHandling) _handleCoreEvent:withReplyEvent:] ()  #92 0x920c446c in -[NSAppleEventManager dispatchRawAppleEvent:withRawReply:handlerRefCon:] ()  #93 0x920c4230 in _NSAppleEventManagerGenericHandler ()  #94 0x929c0de6 in aeDispatchAppleEvent ()  #95 0x929c0ce5 in dispatchEventAndSendReply ()  #96 0x929c0bf2 in aeProcessAppleEvent ()  #97 0x97cae381 in AEProcessAppleEvent ()  #98 0x90c77ed2 in _DPSNextEvent ()  #99 0x90c7750a in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] ()  #100 0x90c3969b in -[NSApplication run] ()  #101 0x90c31735 in NSApplicationMain ()  #102 0x0000262e in start ()  (gdb)   

When you debug a bit more and print the NSImage instance it is trying to draw ...

(gdb) frame 60  (gdb) po *(int*)($ebp+8)  <NSImage 0x1261f10 Name=ForwardTemplate Size={20, 20} Reps=(     NSPDFImageRep 0x18abc30 Size={20, 20} ColorSpace=NSCalibratedRGBColorSpace BPS=0 Pixels=20x20 Alpha=NO  )>  

This is one of the template images for the "forward transport" custom button in the application's toolbar. (see http://www.cancelmonday.com/beatler for a screen shot)

I am just looking for ideas on what I can do to try and debug this further as the hard thing is that it is only this one user that is reporting this issue and I cannot reproduce it locally.

Any help would be greatly appreciated.

Update

Thanks to diciu I ran ...

thread apply all bt  

This did show up a problem with a load of threads sat waiting and an example stack for a thread is ...

Thread 365 (process 1866):  #0  0x92542782 in __semwait_signal ()  #1  0x9254243e in _pthread_cond_wait ()  #2  0x925440d8 in pthread_cond_wait$UNIX2003 ()  #3  0x920b7b5e in -[NSCondition wait] ()  #4  0x920a5531 in -[NSObject(NSThreadPerformAdditions) performSelector:onThread:withObject:waitUntilDone:modes:] ()  #5  0x920b7cb7 in -[NSObject(NSThreadPerformAdditions) performSelectorOnMainThread:withObject:waitUntilDone:] ()  #6  0x000183e8 in -[BLImageLoader main] ()  #7  0x920b73b3 in -[__NSOperationInternal start] ()  #8  0x920b6fe0 in ____startOperations_block_invoke_2 ()  #9  0x925487b8 in _dispatch_call_block_and_release ()  #10 0x9253a97e in _dispatch_worker_thread2 ()  #11 0x9253a401 in _pthread_wqthread ()  #12 0x9253a246 in start_wqthread ()  

These threads do update the UI but it is always done through ...

[item performSelectorOnMainThread:@selector(setDisplayImage:) withObject:image waitUntilDone:YES];  

I thought this would be safe, are there any issues with lots of threads e.g. 400+ all wanting to ...

performSelectorOnMainThread

...within the same time period?


Solution:1

Your main thread is blocked waiting for a condition to happen (pthread_cond_wait$UNIX2003).

Are you updating the UI from a non-main thread?

In gdb

thread apply all bt  

will show you the state of all your application's threads - it may be that your main thread is blocked by some other thread doing UI stuff.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »