Please explain how one thread can interleave event handlers

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
Virchanza
I live to help wx-kind
I live to help wx-kind
Posts: 172
Joined: Sun Jul 19, 2009 6:12 am

Please explain how one thread can interleave event handlers

Post by Virchanza »

I was looking through the code for my Dynamo program, and I saw this:

Code: Select all

void Dialog_Main::OnButtonClick_See_Detailed_MAC_Info( wxCommandEvent& event )
{
    (new Dialog_Detailed_MAC_Info(this,p))->ShowModal();
    
    /* This function call doesn't return until the
       dialog disappears, however wxWidgets has some
       sort of sorcery going on in the background that lets it
       jump out and process other events, then come
       back to finish this one. */
       
    /* Do more processing after dialog disappears */
}
So wxWidgets is able to execute through a portion of the code of an event handler, pause the event handler, enter into another event handler, and then return to the original event handler that was paused.

Can someone point me to the code in wxWidgets that achieves this behaviour even though there is only one GUI Thread? I imagine it must use a signal to interrupt the thread, because I can't think how else it could interleave event handlers. I'm very interested to see how this works. Can you point me to the .cpp file in wxWidgets that does this?
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Please explain how one thread can interleave event handlers

Post by ONEEYEMAN »

Hi,
Dialog peocessing does create a temporary event loop.
However, as you already know - wxWidgets is based on the native behavior, so all this is done partially inside platform/toolkit code, but some is done inside wxWidgets.

Keep in mind that popping up a dialog is not considered a thread interruption - you are creating a dialog object and showing it to a user in a context of the same GUI thread you are running. You just create a temporary event loop for the dialog (TLW). Remember event loop is not considered a thread.

Thank you.
Post Reply