I have a runloop running in an NSThread. In this thread is a timer which fires 
every 2 seconds. In the timer, I check [NSThread isCancelled] and if so, stop 
the runloop via CFRunLoopStop.

The runloop is run via runUntilDate:distantFuture.

Shouldn't runUntilDate terminate once CFRunLoopStop has been called on it?

Here is the pertinent code:


- (void)gatheringTimer:(NSTimer*)timer
{
        if ([[NSThread currentThread] isCancelled])
        {
                [timer invalidate];
                CFRunLoopStop(CFRunLoopGetCurrent());
                return;
        }
        
// Real code goes here to do handle the timer
}

- (void)doGathering:(id)object
{
        NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
        
        [NSTimer scheduledTimerWithTimeInterval:2.0 
                                                                         
target:self
                                                                   
selector:@selector(gatheringTimer:)
                                                                   userInfo:nil
                                                                        
repeats:YES];
        
        [[NSRunLoop currentRunLoop] runUntilDate:[NSDate distantFuture]];
        
        [pool drain];
}

- (void)startGathering
{
        if (!_gatheringThread)
        {
                _gatheringThread = [[NSThread alloc] initWithTarget:self 
selector:@selector(doGathering:) object:nil];
                [_gatheringThread start];
        }
}

- (void)stopGathering
{
        if (_gatheringThread)
        {
                [_gatheringThread cancel];
                [_gatheringThread release];
                _gatheringThread = nil;
        }
}


I have verified that CFRunLoopStop is being called, but doGathering never 
finishes

Any ideas?

Thanks

Matt

_______________________________________________

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

Reply via email to