Re: UI refresh in background thread while [NSTask waitUntilExit]
On Apr 26, 2011, at 2:55 AM, Vera Tkachenko wrote: > In my app I need to determine if some app if properly codesigned. To do this > I just invoke "/usr/bin/codesign" and analyse return value. To invoke it I > use NSTask and launch it in background thread. Everything works fine excepts > strange crash I get sometimes from our customers. While NSTask is waiting for > command to finish (waitUntilExit) UI starts to update in background thread... > which causes crashes. I now that's improper to do any UI related stuff in > background threads. And I don't force UI update explicitly. > > But why it's get updated while waiting? -[NSTask waitUntilExit] runs the current thread's run loop in the default mode. Because of this, it is kind of dangerous -- it will service any input sources, timers, delayed performSelector... invocations, etc. that are scheduled in the default mode. Now, the normal way to work around this is to run it on a secondary thread where you have a degree of control over what is scheduled on the run loop. That's what you are doing, apparently. So, the question is: what is scheduling a timer or delayed performSelector... on that thread's run loop? It is either some of your own code, or you are invoking something in Cocoa which does that as a side effect. Perhaps something is invoking one of the -setNeedsDisplay... methods of an NSView, which might implicitly schedule -[NSWindow displayIfNeeded] onto the thread's run loop. Regards, Ken ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
UI refresh in background thread while [NSTask waitUntilExit]
Hello, In my app I need to determine if some app if properly codesigned. To do this I just invoke "/usr/bin/codesign" and analyse return value. To invoke it I use NSTask and launch it in background thread. Everything works fine excepts strange crash I get sometimes from our customers. While NSTask is waiting for command to finish (waitUntilExit) UI starts to update in background thread... which causes crashes. I now that's improper to do any UI related stuff in background threads. And I don't force UI update explicitly. But why it's get updated while waiting? Part of stack trace of crashed thread: 19 com.apple.AppKit0x915e8d40 -[NSWindow displayIfNeeded] 204 20 com.apple.Foundation0x93b6d9d5 __NSFireDelayedPerform 537 21 com.apple.CoreFoundation0x95634adb __CFRunLoopRun 8059 22 com.apple.CoreFoundation0x95632464 CFRunLoopRunSpecific 452 23 com.apple.CoreFoundation0x95632291 CFRunLoopRunInMode 97 24 com.apple.Foundation0x93be6805 -[NSConcreteTask waitUntilExit] 273 NSTask launching code: // create task and pipe objects NSTask *task = [[NSTask alloc] init]; NSPipe *outputPipe = [[NSPipe alloc] init]; NSPipe *errorPipe = [[NSPipe alloc] init]; // setup binary and arguments [task setLaunchPath:cmd]; [task setStandardOutput:outputPipe]; // and all error output goes to our pipe, not console [task setStandardError:errorPipe]; [task setArguments:args]; // launch task [task launch]; [task waitUntilExit]; [[errorPipe fileHandleForReading] closeFile]; [[outputPipe fileHandleForReading] closeFile]; terminationStatus = [task terminationStatus]; [task terminate]; // just in case Thanks for your help, Vera Tkachenko___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com