User forums > Help

Problem with the abort build button

<< < (3/3)

thomas:

--- Quote from: Urxae on November 02, 2005, 10:38:31 am ---I beg to differ. Knowing it not to work doesn't mean it isn't still a bug when it doesn't :P. Besides, as this thread shows some people expect it to actually work ;) (As did I the first time I pushed the Big Red ButtonTM).
--- End quote ---

It works, and it is no bug. What Code::Blocks does is perfectly correct and legal. It is just that SIGTERM (or signals in general) does not exist on Windows.
So what the abort button effectively does is stop the run queue, thus no more processes are launched. Everything works as it should, really.


--- Quote from: Urxae on November 02, 2005, 10:38:31 am ---According to
--- End quote ---
The wxWidgets documentation is rubbish, bluntly said. It often makes claims which are not in concordance with reality. For example, the documentation encourages to use wxMilliSleep instead of usleep(3) because it is MT safe. What wxMilliSleep really does is multiply by 1000 and call the platform-dependent usleep, Sleep, or nanosleep function. In my humble opinion, a multiply does not greatly increase thread safety.

The issue with wxKill is similar. While it really sends signals on Unix, what wxKill does on Windows is this:
- If signal is SIGKILL, it calls TerminateProcess
- If signal is SIGNONE, the function returns immediately
- If signal is *anything* except the two above, it posts WM_QUIT to any windows it can find

You could argue that WM_QUIT kind of simulates a SIGTERM for Windows programs, but that is really not the case. SIGTERM is meant to say "please go away, gracefully", and an application is not even required to actually follow it.
WM_QUIT just ends the message loop, and the program exits without much opportunity for cleanup.
Using WM_CLOSE instead would be an improvement at least insofar as the program is not just knocked out of its message loop, but it would of course still not work for non-GUI programs.

Edit: typo

Michael:
Hello,

Sorry, but why you say that "It is just that SIGTERM (or signals in general) does not exist on Windows."?

After the wxWidgets doc:

int wxKill(long pid, int sig = wxSIGTERM, wxKillError *rc = NULL, int flags = 0)

wxSIGNONE, wxSIGKILL and wxSIGTERM have the same meaning under both Unix and Windows but all the other signals are equivalent to wxSIGTERM under Windows.

Thank you very much.

Best wishes,
Michael

mandrav:
What he 's saying is that when things don't work as expected, take a peek in the code. Don't always rely on the documentation...

thomas:
If you look at src/msw/utils/utils.cpp  (abbreviated):

int wxKill(long pid, wxSignal sig, wxKillError *krc, int flags)
{
...
    HANDLE hProcess = ::OpenProcess(SYNCHRONIZE | PROCESS_TERMINATE |
                                                     PROCESS_QUERY_INFORMATION, FALSE, (DWORD) pid);
    if ( hProcess == NULL )
    {
...
        return -1;
    }

    bool ok = true;
    switch ( sig )
    {
        case wxSIGKILL:
            // kill the process forcefully returning -1 as error code
            if ( !::TerminateProcess(hProcess, (UINT)-1) )
            {
                wxLogSysError(_("Failed to kill process %d"), pid);

                if ( krc )
                {
                    // this is not supposed to happen if we could open the
                    // process
                    *krc = wxKILL_ERROR;
                }

                ok = false;
            }
            break;

        case wxSIGNONE:
            // do nothing, we just want to test for process existence
            break;

        default:
            // any other signal means "terminate"
            {
                wxFindByPidParams params;
                params.pid = (DWORD)pid;

...
                if ( !::EnumWindows(wxEnumFindByPidProc, (LPARAM)&params) )
                {
                    // did we find any window?
                    if ( params.hwnd )
                    {
...
                        if ( !::PostMessage(params.hwnd, WM_QUIT, 0, 0) )
                        {
                            wxLogLastError(_T("PostMessage(WM_QUIT)"));
                        }
                    }
...
                }
                else // no windows for this PID
                {
...
                    ok = false;
                }
            }
    }
...

    ::CloseHandle(hProcess);
...
}
You see that what the documentation tells you differs from what actually happens.

Michael:
Hello,

Yes, I see. Thank you very much for the explanation.

Best wishes,
Michael

Navigation

[0] Message Index

[*] Previous page

Go to full version