Re: Stopping an NSRunLoop OR getting NSDistributedNotificationCenter notifications
Re: Stopping an NSRunLoop OR getting NSDistributedNotificationCenter notifications
- Subject: Re: Stopping an NSRunLoop OR getting NSDistributedNotificationCenter notifications
- From: Chris Kane <email@hidden>
- Date: Mon, 19 Jun 2006 10:01:33 -0700
On Jun 19, 2006, at 9:50 AM, Tom Harrington wrote:
On 6/18/06, James Bucanek <email@hidden> wrote:
I've got a background daemon (Foundation command-line tool) that
performs user-defined tasks at specific times.
I've never figured out how to get an NSRunLoop to exit in a timely
fashion.
In a similar-sounding situation I found that using CFRunLoop nicely
solved the problem. I'd enter the run loop with CFRunLoopRun(). On
receiving the appropriate notification I'd stop the run loop with
CFRunLoopStop(CFRunLoopGetCurrent()). Worked like a charm, even with
Cocoa notifications.
The reason I don't promote CFRunLoopStop() is that it has a very
subtle behavior -- it only stops the topmost activation of the run
loop on the thread's call stack. Since the run loop can be run
reentrantly, depending on what is going on at the moment you call
CFRunLoopStop(), it may not actually stop your CFRunLoopRun() call,
but rather a higher activation, where it may be freely ignored by the
caller of CFRunLoop.
And of course, devilishly, this stopping technique is one of those
things that might appear to work most of the time, and very
occasionally doesn't.
Chris Kane
Cocoa Frameworks, Apple
_______________________________________________
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