[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Does signal trap of CTRL-CLOSE event allowable to be used on windows
From: |
Michael Goffioul |
Subject: |
Re: Does signal trap of CTRL-CLOSE event allowable to be used on windows? |
Date: |
Thu, 14 Jul 2011 09:19:56 +0100 |
The main problem with these signals in Win32 is that they
are not executed in octave main thread, but in a separate
thread. The pain is then to make the main octave thread to
jump at a specific code to execute from the thread handling
the signal. This is what the CTRL-C handler is trying to do,
but fails 50% of the time.
Although in the case of CTRL_CLOSE_EVENT, we might
tolerate to exit octave from the signal thread instead of the
main thread, but I wouldn't bet on a safe exit, especially if
some exit handlers have been installed.
Michael.
On Thu, Jul 14, 2011 at 6:40 AM, Tatsuro MATSUOKA <address@hidden> wrote:
> Hello
>
> I have execute quick hack the code.
>
> *******************************************************
> exporting patch:
> <fdopen>
> # HG changeset patch
> # User Tatsuro MATSUOKA <address@hidden>
> # Date 1310598111 -32400
> # Node ID bfc000b283dab3600345e787388cf5df3752861a
> # Parent 0ca5672d5f1ab4be79b7f1c6053e5cbf7e31c253
>
> Quick hack to avoid close console error by right upper button
> on windows.
>
> diff -r 0ca5672d5f1a -r bfc000b283da src/sighandlers.cc
> --- a/src/sighandlers.cc Thu Jul 07 19:16:14 2011 -0400
> +++ b/src/sighandlers.cc Thu Jul 14 08:01:51 2011 +0900
> @@ -433,6 +433,8 @@
> break;
>
> case CTRL_CLOSE_EVENT:
> + clean_up_and_exit (0);
> + break;
> case CTRL_LOGOFF_EVENT:
> case CTRL_SHUTDOWN_EVENT:
> default:
> ********************************************************
>
> octave:1> graphics_toolkit fltk
> octave:2> peaks
> octave:3>
> (Then press [x] button)
> Some message are coming out but console closes too fast what happened to see.
>
> As you said, it seem not to be easy to quit octave clearly.
>
> Regards
>
> Tatsuro
>
> The above seemed to work test like the below
>
>
>
> but perhaps need to test further.
> Any suggestions ?
>
> --- On Wed, 2011/7/13, Michael Goffioul <address@hidden> wrote:
>
>> That's worth a try. But from the experience of handling CTRL-C event
>> (which usually crashes
>> octave), it may not be as easy as it sounds.
>>
>> Michael.
>>
>>
>> On Tue, Jul 12, 2011 at 7:36 PM, Tatsuro MATSUOKA <address@hidden> wrote:
>> > Hello
>> >
>> > Pressing 'X' button on the right upper side windows console always induce
>> > error.
>> > If we use SetConsoleCtrlHandler function and trap CTRL-CLOSE event, we
>> > may eliminate annoy the error.
>> >
>> > In src/sighandlers.cc, I found
>> >
>> > #**From here
>> > #ifdef USE_W32_SIGINT
>> > static BOOL CALLBACK
>> > w32_sigint_handler (DWORD sig)
>> > {
>> > const char *sig_name;
>> >
>> > switch(sig)
>> > {
>> > case CTRL_BREAK_EVENT:
>> > sig_name = "Ctrl-Break";
>> > break;
>> > case CTRL_C_EVENT:
>> > sig_name = "Ctrl-C";
>> > break;
>> > case CTRL_CLOSE_EVENT:
>> > sig_name = "close console";
>> > break;
>> > case CTRL_LOGOFF_EVENT:
>> > sig_name = "logoff";
>> > break;
>> > case CTRL_SHUTDOWN_EVENT:
>> > sig_name = "shutdown";
>> > break;
>> > default:
>> > sig_name = "unknown console event";
>> > break;
>> > }
>> >
>> > switch(sig)
>> > {
>> > case CTRL_BREAK_EVENT:
>> > case CTRL_C_EVENT:
>> > w32_raise (SIGINT);
>> > break;
>> >
>> > case CTRL_CLOSE_EVENT:
>> > case CTRL_LOGOFF_EVENT:
>> > case CTRL_SHUTDOWN_EVENT:
>> > default:
>> > // We should do the following:
>> > // clean_up_and_exit (0);
>> > // We can't because we aren't running in the normal Octave thread.
>> > user_abort(sig_name, sig);
>> > break;
>> > }
>> >
>> > // Return TRUE if the event was handled, or FALSE if another handler
>> > // should be called.
>> > // FIXME check that windows terminates the thread.
>> > return TRUE;
>> > }
>> > # ***********here END
>> >
>> > If we manipulate arround
>> > case CTRL_CLOSE_EVENT:
>> >
>> > we may avoid the annoying the error.
>> >
>> > Regards
>> >
>> > Tatsuro
>> >
>> >
>> >
>>
>