Re: SIGINT with gtk_main



Chris Vine wrote:
On Wednesday 21 March 2007 17:50, Michiel Jan Laurens de Hoon wrote:

For my application, I need to run gtk_main but I want to quit gtk_main
when either input is available on stdin or the user presses Ctrl-C.
[snip]

You can write to a pipe in the signal handler (assuming you are using Unix as your question implies), as write() is async-signal-safe - but set the pipe non-blocking as in the unlikely event of it filling up and blocking on write you will deadlock the program. You can watch on the pipe in the main loop using GIOChannel.

For this approach I wrote some code to simplify this:
http://www.knitter.ch/src/gunixsignal/

But the other approach with the flag is not bad too. The only advantage
of the pipe compared with the flag is that the pipe won't miss a Signal
while the flag may miss a signal. (if you send two signal within your
100ms interval you don't know if there was more than one).

Cheers, Andy




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]