Re: Cocoa & signal handlers
Re: Cocoa & signal handlers
- Subject: Re: Cocoa & signal handlers
- From: Greg Parker <email@hidden>
- Date: Mon, 10 Dec 2001 14:04:53 -0800
On Wednesday, December 5, 2001, at 10:02 AM, Ingvar Nedrebo wrote:
Greg,
Thanks! I had come to suspect as much, so what I'll do is to
use a global variable, set my NSTimer to 2 secs and just count
up to my period of ~15 minutes. The CPU overhead should still
be neglible.
But out of curiosity and because of an upcoming project where
this could be more of an issue: One of my thoughts was to open
an NSPipe and use -readInBackgroundAndNotify; then in the
signal handler do a non-blocking raw write(2) directly on
the pipe. Would that have a chance of working?
You may be able to use raw write() on a pipe from a signal
handler. I haven't looked at Darwin's implementation, so I
can't say whether it's completely safe.
You may also be able to use CFRunLoop APIs from CoreFoundation to
wake up the run loop directly. -readInBackgroundAndNotify will
need to do something like this internally, so if this isn't safe
then neither is the pipe.
1. Create a CFRunLoopObserver that runs on kCFRunLoopAfterWaiting
and checks the global variable. Attach the observer to the
app's run loop.
2. In the signal handler, set the global variable and then
call CFRunLoopWakeUp(), which will waken the run loop and run
the observer.
(This is not official Apple advice. The above system has not been
tested. Your mileage may vary.)
--
Greg Parker email@hidden Java & Objective C