Re: SIGIO and AppKit main loop
Re: SIGIO and AppKit main loop
- Subject: Re: SIGIO and AppKit main loop
- From: Kyle Moffett <email@hidden>
- Date: Sun, 28 Mar 2004 22:46:06 -0500
On Mar 28, 2004, at 22:03, Michael Rothwell wrote:
I think I have arrived at the final word on using Objective-C in signal
handlers of any type: "don't."
SIGIO can safely be filed under "never use" or "doesn't work," your
choice.
Too bad, really. Event-driven I/O would be useful. I have two options
remaining -- poll with e.g., select(), or block on recvfrom() in a
thread and notify.
My personal preference for using signals in programs is to have all the
signal handlers just atomically set a volatile integer to 1. Then I
have
the main event loop just run a simple "if (got_sig_quit)" and set it to
zero inside the if statement. It never drops signals, doesn't have any
of
the reentrancy issues that normally go with libc, and tends to be really
easy to maintain and improve. Here's an example from one of my C
programs:
static volatile int got_sig_quit;
static void _sig_quit(int s) {
got_sig_quit = 1;
}
void install_handlers (void) {
signal(SIGQUIT,&_sig_quit);
}
int handle_sig_quit(void) {
if (got_sig_quit) {
got_sig_quit = 0;
return 1;
} else return 0;
}
Note that I am really careful about ordering and the use of volatile to
make sure that I never lose any signals.
Cheers,
Kyle Moffett
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCM/CS/IT/U d- s++: a17 C++++>$ UB/L/X/*++++(+)>$ P+++(++++)>$
L++++(+++) E W++(+) N+++(++) o? K? w--- O? M++ V? PS+() PE+(-) Y+
PGP+++ t+(+++) 5 X R? tv-(--) b++++(++) DI+ D+ G e->++++$ h!*()>++$ r
!y?(-)
------END GEEK CODE BLOCK------
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.