Re: NSProgressIndicator thread crash (race condition in AppKit)
Re: NSProgressIndicator thread crash (race condition in AppKit)
- Subject: Re: NSProgressIndicator thread crash (race condition in AppKit)
- From: Florent Pillet <email@hidden>
- Date: Thu, 24 Feb 2005 10:32:33 +0100
I think I understand what's happening, and where the bug sits in the
AppKit.
In my application, I have several threads running and at some point I
decide that the sheet containing the progress indicator should go away.
For this, I'll do:
[self performSelectorOnMainThread:@selector(removeSheet:)
withObject:nil waitUntilDone:NO];
Now what may happen is that the method executing on the main thread
does remove the sheet while the progress indicator's heartBeat timer is
still scheduled. I suspect that when you remove a sheet, the heartBeat
timer doesn't get immediately invalidated. This would likely cause a
crash as the view containing the progress indicator is not on screen
anymore (BUT in my case, the view is -NOT- released).
To shield against this, I have added two things in my method that
removes the sheet:
[progressIndicator stopAnimation:self];
[progressIndicator setIndeterminate:NO];
[NSApp endSheet:mySheet];
Now this will be safe ONLY if the stopAnimation: method properly
invalidates the timer. From what I've seen from the log, this thread is
correctly using semaphores so the odds are good that it will prevent
the crash. I can't be sure as I don't have access to the AppKit source
code, but the code above seems like it's the only way to properly do
things.
Any confirmation (John?) would be good. Further examination of the
crash log reveals that the AppKit uses a semaphore only when -changing-
something in a view hierarchy. In other words, while it is removing the
view from the screen, the heartBeat thread is still running. This
corroborates what we see in the crash log, which is:
- Main thread: -[NSViewHierarchyLock lockForWriting] + 0x194, waiting
on a semaphore
- Thread 2 (crashes): -[NSView lockFocusIfCanDraw] + 0x2a4
There definitely is a race condition in the AppKit. I'll file a
detailed bug report on this one. For reference, I re-include the crash
log at bottom of this email. This happens on 10.3.8.
Florent
On 24 févr. 05, at 09:46, j o a r wrote:
On 2005-02-24, at 09.23, Florent Pillet wrote:
Today I got a report of a crash in one of my apps. Examining the
crash log the user sent reveals that this is the thread updating the
progress bar that crashed. In my app, I have a sheet that first uses
a normal progress bar, then switches the progress bar to infinite
until the task is complete and the sheet is removed.
I suspect the call to [NSApp endSheet:] may have removed the sheet
while the progress bar thread was still scheduled. I have added a
[progressBar setIndeterminate:NO] just before the endSheet: call, but
I wanted to have expert's advice about this crash.
Most likely this is not a bug in your app. I would guess it's related
to:
<http://www.cocoabuilder.com/archive/message/cocoa/2004/12/4/123036>
<http://www.cocoabuilder.com/archive/message/cocoa/2005/1/6/125170>
j o a r
Exception: EXC_BAD_ACCESS (0x0001)
Codes: KERN_PROTECTION_FAILURE (0x0002) at 0x0000004c
Thread 0:
0 libSystem.B.dylib 0x90016f48
semaphore_wait_signal_trap +
0x8
1 libSystem.B.dylib 0x9000e790 _pthread_cond_wait +
0x270
2 com.apple.AppKit 0x92dca8ec -[NSViewHierarchyLock
lockForWriting] + 0x194
3 com.apple.AppKit 0x92dd51d8 -[NSView
_displayRectIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:] +
0x114
4 com.apple.AppKit 0x92dee274 -[NSView
displayIfNeeded] +
0xa8
5 com.apple.AppKit 0x92dfef4c -[NSWindow
displayIfNeeded] +
0xb4
6 com.apple.AppKit 0x92ddf5ac
_handleWindowNeedsDisplay +
0xe0
7 com.apple.CoreFoundation 0x90191ca0 __CFRunLoopDoObservers
+ 0x194
8 com.apple.CoreFoundation 0x9019153c __CFRunLoopRun + 0x18c
9 com.apple.CoreFoundation 0x90195e8c CFRunLoopRunSpecific +
0x148
10 com.apple.HIToolbox 0x927d5f60
RunCurrentEventLoopInMode +
0xac
11 com.apple.HIToolbox 0x927dc6c8 ReceiveNextEventCommon
+ 0x17c
12 com.apple.HIToolbox 0x927fe6a0
BlockUntilNextEventMatchingListInMode + 0x60
13 com.apple.AppKit 0x92dd2e44 _DPSNextEvent + 0x180
14 com.apple.AppKit 0x92de98c8 -[NSApplication
nextEventMatchingMask:untilDate:inMode:dequeue:] + 0x74
15 com.apple.AppKit 0x92dfdc30 -[NSApplication run] +
0x21c
16 OmniAppKit 0x3b207950 -[OAApplication run] +
0x94
17 com.apple.AppKit 0x92eba2b8 NSApplicationMain +
0x1d0
18 SyncBuddy 0x0000aa08 0x1000 + 0x9a08
19 dyld 0x8fe1a558 _dyld_start + 0x64
Thread 2 Crashed:
0 com.apple.AppKit 0x92dc50c4 -[NSView
lockFocusIfCanDraw]
+ 0x2a4
1 com.apple.AppKit 0x92de9ea0 -[NSView lockFocus] +
0x28
2 com.apple.AppKit 0x92e21f68 -[NSUIHeartBeat
lockFocusForView:inRect:needsTranslation:] + 0x224
3 com.apple.AppKit 0x92de7954 -[NSProgressIndicator
heartBeat:] + 0x640
4 com.apple.AppKit 0x92dcaf2c -[NSUIHeartBeat
_heartBeatThread:] + 0x3d8
5 com.apple.Foundation 0x90a39b74 forkThreadForFunction
+ 0x6c
6 libSystem.B.dylib 0x900246e8 _pthread_body + 0x28
--
Florent Pillet http://www.florentpillet.com
Freelance software developer/consultant - Palm OS & Mac OS X
ICQ: 117292463 Skype: callto://florent.pillet
_______________________________________________
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