• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Runloop not being stopped by CFRunLoopStop?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Runloop not being stopped by CFRunLoopStop?


  • Subject: Re: Runloop not being stopped by CFRunLoopStop?
  • From: Jeff Johnson <email@hidden>
  • Date: Mon, 04 Jul 2011 11:58:31 -0500

Hi Matt.

Is there a reason that you're using -[NSRunLoop runUntilDate:] instead of CFRunLoopRun()?

According to the documentation, runUntilDate: "runs the receiver in the NSDefaultRunLoopMode by repeatedly invoking runMode:beforeDate: until the specified expiration date." So even if CFRunLoopStop() stops one invocation of runMode:beforeDate:, it won't necessarily stop subsequent invocations. Furthermore, "Manually removing all known input sources and timers from the run loop is not a guarantee that the run loop will exit. Mac OS X can install and remove additional input sources as needed to process requests targeted at the receiver’s thread. Those sources could therefore prevent the run loop from exiting."

-Jeff


On Jul 4, 2011, at 11:36 AM, Matt Gough wrote:

> 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 (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

  • Follow-Ups:
    • Re: Runloop not being stopped by CFRunLoopStop?
      • From: Matt Gough <email@hidden>
References: 
 >Runloop not being stopped by CFRunLoopStop? (From: Matt Gough <email@hidden>)

  • Prev by Date: Runloop not being stopped by CFRunLoopStop?
  • Next by Date: Re: Runloop not being stopped by CFRunLoopStop?
  • Previous by thread: Runloop not being stopped by CFRunLoopStop?
  • Next by thread: Re: Runloop not being stopped by CFRunLoopStop?
  • Index(es):
    • Date
    • Thread