Run Loop in Tool Idles for 60.0 seconds before exitting
Run Loop in Tool Idles for 60.0 seconds before exitting
- Subject: Run Loop in Tool Idles for 60.0 seconds before exitting
- From: Jerry Krinock <email@hidden>
- Date: Sun, 4 Apr 2010 14:06:18 -0700
My app package includes a tool which can be invoked to do some of the work that the main app normally does, kind of like xcodebuild. In the tool, I create and run a run loop with this code:
while (
![[AgentPerformer sharedPerformer] isDone]
&&
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
beforeDate:[NSDate distantFuture]]) {
NSLog(@"Did Run") ;
}
NSLog(@"Exitting run loop") ;
The work to be done involves about 3 dozen dependent NSOperations, so the "Done Run" logs about 3 dozen times in 10 seconds or so. These operations are also logged. The last operation sets the sharedPerformer's isDone to YES. I expect the run loop to exit immediately, but upon testing *most* builds it sits idle for exactly 60 seconds before "Exitting run loop". Sometimes, seemingly by throwing in extra NSLogs, it exits immediately as expected, but this behavior is not repeatable in any way that I can comprehend.
A Sample taken during the 60 seconds of idle time is shown below.
I cannot find any suspicious 60.0-second timeout in my code. Has anyone ever seen the Cocoa runtime apply such a timeout? What might be wrong with my design?
I was wondering if the run loop needed "one last kick", so I added a timer to the last operation. (See code at bottom of post). But that timer never fires, which tells me that the timer's thread is blocked, and this is probably the same thread which is waiting 60 seconds. Who might be doing that? Can't find any clues in Threading Programming Guide ▸ Run Loops.
Jerry Krinock
Sampling process 33013 for 3 seconds with 1 millisecond of run time between samples
Sampling completed, processing symbols...
Analysis of sampling BookMacster-Worker (pid 33013) every 1 millisecond
Call graph:
2747 Thread_498571 DispatchQueue_1: com.apple.main-thread (serial)
2747 start
2747 main
2747 -[NSRunLoop(NSRunLoop) runMode:beforeDate:]
2747 CFRunLoopRunInMode
2747 CFRunLoopRunSpecific
2747 __CFRunLoopRun
2747 mach_msg
2747 mach_msg_trap
2747 Thread_498576 DispatchQueue_2: com.apple.libdispatch-manager (serial)
2747 start_wqthread
2747 _pthread_wqthread
2747 _dispatch_worker_thread2
2747 _dispatch_queue_invoke
2747 _dispatch_mgr_invoke
2747 kevent
Total number in stack (recursive counted multiple, when >=5):
Sort by top of stack, same collapsed (when >= 5):
kevent 2747
mach_msg_trap 2747
Sample analysis of process 33013 written to file /dev/stdout
/********* "One Last Kick" in the final operation *******/
- (void)byebye:(NSTimer*)timer {
NSLog(@"Bye Bye") ; // Never logs
}
/* Method invoked by the final NSOperation's "main" wrapper*/
- (void)terminateWork {
NSLog(@"-->> %s", __PRETTY_FUNCTION__) ;
[NSTimer scheduledTimerWithTimeInterval:5.0
target:self
selector:@selector(byebye:)
userInfo:nil
repeats:NO] ;
[[AgentPerformer sharedPerformer] setIsDone:YES] ;
NSLog(@"<<-- %s", __PRETTY_FUNCTION__) ;
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden