Re: Cocoa & signal handlers
Re: Cocoa & signal handlers
- Subject: Re: Cocoa & signal handlers
- From: Douglas Davidson <email@hidden>
- Date: Mon, 10 Dec 2001 16:15:42 -0800
On Monday, December 10, 2001, at 03:55 PM, Greg Parker wrote:
My understanding from the documentation of readInBackgroundAndNotify
was that it does the read in a separate thread -- on the face
of it it looks fairly safe to do a single system call in a signal
handler, provided of course that the write doesn't block, but
I'm only writing 4 bytes (the signal number).
You may be right, the write() method may be safe even if waking the run
loop from the signal handler is not. -readInBackgroundAndNotify probably
works like CFSocket with a second thread running select(). That thread
does need to wake up the run loop, but it doesn't need to talk to the
run loop during the signal handler.
Yes, it is something along these lines. Another option would be to use
CFSocket rather than NSFileHandle to do the receiving; that may be
somewhat lighter-weight. Another alternative that might seem natural
would be to use a Mach message rather than a BSD pipe, and receive it
with a CFMachPort.
However, I cannot myself guarantee that either a write() call or sending
a Mach message is safe during the execution of a signal handler.
Douglas Davidson