Deadlock with -setApplicationIconImage in a drawing thread
Deadlock with -setApplicationIconImage in a drawing thread
- Subject: Deadlock with -setApplicationIconImage in a drawing thread
- From: David Sinclair <email@hidden>
- Date: Thu, 16 Jan 2003 22:00:24 -0800
I am trying to implement a little Dock icon animation for my app's
icon. It consistently gets into a deadlock. I use
detachDrawingThread:toTarget:withObject: as follows, which I understood
from messages in the archives would set things up correctly to allow
drawing in a secondary thread:
[NSApplication
detachDrawingThread:@selector(animateDockIconStatic:) toTarget:self
withObject:[NSNumber numberWithInt:0]];
(I use a thread rather than a timer as it occurs during app startup --
not during a run loop.)
The method in question calls -setApplicationIconImage: -- is that not
thread safe?
Here's the secondary thread method (the dockIconStaticAnimation
instance variable is initialized to 1, and zeroed when the animation
should stop):
- (void)animateDockIconStatic:(NSNumber *)ignored
{
while (dockIconStaticAnimation)
{
NSString *imageName = [NSString
stringWithFormat:@"BadgeStatic%d", dockIconStaticAnimation];
[NSApp setApplicationIconImage:[NSImage imageNamed:imageName]];
if (dockIconStaticAnimation < BADGE_STATIC_NUM_ANIMATIONS)
dockIconStaticAnimation++;
else
dockIconStaticAnimation = 1;
NSDate *sleepDate = [NSDate dateWithTimeIntervalSinceNow:0.1];
[NSThread sleepUntilDate:sleepDate];
}
}
I tried adding a NSRecursiveLock to the above method, but it didn't
help.
The thread frames are as follows; notice that one is doing a
_NSAppKitLock, while the other does _NSAppKitImgLock:
Animation thread (3):
#0 0x9003eaa8 in semaphore_wait_signal_trap
#1 0x9003e8c4 in pthread_cond_wait
#2 0x907e1cc4 in -[NSRecursiveLock lock]
#3 0x930753c0 in _NSAppKitLock
#4 0x930d9cb0 in -[NSImageCell drawInteriorWithFrame:inView:]
#5 0x93123784 in +[NSImageRep
_imageRepClassForFileNameExtension:andHFSFileType:]
#6 0x930f3358 in -[NSImage _expandRep:]
#7 0x9309190c in -[NSImage _expand]
#8 0x93081954 in -[NSImage size]
#9 0x93169630 in -[NSApplication _setApplicationIconImage:setDockImage:]
#10 0x0000b108 in -[MainController animateDockIconStatic:] at
MainController.m:192
#11 0x9321a114 in +[NSApplication _startDrawingThread:]
#12 0x9081cd38 in forkThreadForFunction
#13 0x90020d48 in bootstrap_status
Main thread (1):
#0 0x9003eaa8 in semaphore_wait_signal_trap
#1 0x9003e8c4 in pthread_cond_wait
#2 0x907e1cc4 in -[NSRecursiveLock lock]
#3 0x9308cbf4 in _NSAppKitImgLock
#4 0x930a9d8c in -[NSWindow _hasCursorRectsForView:]
#5 0x9318b0dc in +[NSColor _controlColor]
#6 0x930f04cc in -[NSDynamicSystemColor recacheColor]
#7 0x930e6a2c in -[NSDynamicSystemColor initWithSelector:]
#8 0x930ba3f0 in +[NSColor controlColor]
#9 0x930e2484 in +[NSColor colorWithCatalogName:colorName:]
#10 0x930d10b4 in +[NSCatalogColor newWithCoder:zone:]
#11 0x930b9cb4 in -[NSColor initWithCoder:]
#12 0x907e4cf8 in _decodeObject
#13 0x907e552c in _decodeValueOfObjCType
#14 0x907e6ab0 in -[NSUnarchiver decodeValuesOfObjCTypes:]
#15 0x9310dcd8 in -[NSTextFieldCell initWithCoder:]
#16 0x907e4cf8 in _decodeObject
#17 0x907e552c in _decodeValueOfObjCType
#18 0x907e6ab0 in -[NSUnarchiver decodeValuesOfObjCTypes:]
#19 0x930e6cbc in -[NSControl initWithCoder:]
#20 0x9310a480 in -[NSTextField initWithCoder:]
#21 0x907e4cf8 in _decodeObject
#22 0x907e552c in _decodeValueOfObjCType
#23 0x907f32e8 in -[NSUnarchiver decodeValueOfObjCType:at:]
#24 0x907fca30 in -[NSArray initWithCoder:]
#25 0x907e4cf8 in _decodeObject
#26 0x907e552c in _decodeValueOfObjCType
#27 0x907e6ab0 in -[NSUnarchiver decodeValuesOfObjCTypes:]
#28 0x930ad6e8 in -[NSView initWithCoder:]
#29 0x93149ec0 in -[NSCustomView initWithCoder:]
#30 0x907e4cf8 in _decodeObject
#31 0x907e552c in _decodeValueOfObjCType
#32 0x907f32e8 in -[NSUnarchiver decodeValueOfObjCType:at:]
#33 0x907fca30 in -[NSArray initWithCoder:]
#34 0x907e4cf8 in _decodeObject
#35 0x907e552c in _decodeValueOfObjCType
#36 0x907e6ab0 in -[NSUnarchiver decodeValuesOfObjCTypes:]
#37 0x930ad6e8 in -[NSView initWithCoder:]
#38 0x93149ec0 in -[NSCustomView initWithCoder:]
#39 0x907e4cf8 in _decodeObject
#40 0x907e552c in _decodeValueOfObjCType
#41 0x907f32e8 in -[NSUnarchiver decodeValueOfObjCType:at:]
#42 0x907fca30 in -[NSArray initWithCoder:]
#43 0x907e4cf8 in _decodeObject
#44 0x907e552c in _decodeValueOfObjCType
#45 0x907e6ab0 in -[NSUnarchiver decodeValuesOfObjCTypes:]
#46 0x930ad6e8 in -[NSView initWithCoder:]
#47 0x907e4cf8 in _decodeObject
#48 0x907e552c in _decodeValueOfObjCType
#49 0x907e6ab0 in -[NSUnarchiver decodeValuesOfObjCTypes:]
#50 0x9312ff1c in -[NSWindowTemplate initWithCoder:]
#51 0x907e4cf8 in _decodeObject
#52 0x907e552c in _decodeValueOfObjCType
#53 0x907e6ab0 in -[NSUnarchiver decodeValuesOfObjCTypes:]
#54 0x93149800 in -[NSIBObjectData initWithCoder:]
#55 0x907e4cf8 in _decodeObject
#56 0x93123c1c in -[NSMenuItem keyEquivalentModifierMask]
#57 0x930e9e58 in +[NSBundle(NSNibLoading)
_loadNibFile:nameTable:withZone:ownerBundle:]
#58 0x93149098 in +[NSBundle(NSNibLoading)
loadNibFile:externalNameTable:withZone:]
#59 0x93148e58 in +[NSBundle(NSNibLoading) loadNibNamed:owner:]
#60 0x00044040 in -[SplashController showSplash] at
SplashController.m:24
#61 0x0000aa00 in -[MainController applicationDidFinishLaunching:] at
MainController.m:94
#62 0x907eaf7c in _nsNotificationCenterCallBack
#63 0x90168580 in CFStorageDeleteValues
#64 0x90165ca0 in _CFNotificationCenterPostLocalNotification
#65 0x9318a178 in -[NSApplication _sendFinishLaunchingNotification]
#66 0x93161084 in +[NSDocumentController sharedDocumentController]
#67 0x91b56570 in aeProcessAppleEvent
#68 0x91b590cc in AEPutAttributePtr
#69 0x91b56478 in aeProcessAppleEvent
#70 0x96a82c04 in AEProcessAppleEvent
#71 0x9308da78 in _DPSNextEvent
#72 0x9309fb04 in -[NSApplication
nextEventMatchingMask:untilDate:inMode:dequeue:]
#73 0x930b15e4 in -[NSApplication run]
#74 0x9315f6b8 in NSApplicationMain
#75 0x00002434 in main at main.m:13
#76 0x000021b8 in _start at crt.c:267
#77 0x00002038 in start
Any ideas? I've searched mamasam, but everything I've read there
indicates that this code should work... unless I'm missing something?
--
David Sinclair, Dejal Systems, LLC - email@hidden
Let Dejal Simon keep an eye on your sites for changes or failures!
http://www.dejal.com/simon/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.