0

In short I'm trying to implement a GUI to my networking app. Both of them have mainloop() so I'm trying to put them into separate threads and I'm using boost::thread for it.

    //standard initialization of boost::thread
    GuiThread.join();
    NetworkThread.join();

However, above crashes for some reason unknown. I'm searching for any way to do the same thing so any suggestion will be appreciated.

Thanks in advance, Red.

EDIT:

I'm creating boost::thread GuiThread of the wxWidgets mainloop like so:

    boost::thread GuiThread = boost::thread ( boost::bind( &myAppClass::MainLoop(), this));

and Networkthread same way.

then i rewrite wxApp OnRun() function like so:

    int OnRun() {
            GuiThread.join();
            NetworkThread.join();
            return 0;
    }

when i run it ( in vs2010 ), it says: myApp.exe has triggered a breakpoint and if i press continue it stops showing the window, if i press break it shows me assembly.

Red_Dot
  • 41
  • 5
  • Not enough information. What crashes, where crashes, how crashes... – Igor R. Nov 12 '12 at 05:53
  • are you sure it's legitimate to access wxwidgets gui from another thread? You'd better leave this gui loop in the main thead, and start another thread for network loop only. – Igor R. Nov 12 '12 at 10:34

1 Answers1

1

You must run wxWidgets main loop from the same thread that initialized the library. If you want to run it in a thread other than main, it means that you can't use the standard IMPLEMENT_APP() macro but must do the initialization yourself, e.g. by calling wxEntry() manually.

VZ.
  • 21,740
  • 3
  • 39
  • 42
  • I'm sorry but I'm kinda noob with wxWidgets. Can you give more info about calling wxEntry() and can I still keep my main class that handles networking and gui together or will i have to make class that will inherit wxThread for gui alone? – Red_Dot Nov 12 '12 at 20:19
  • In the simplest case it's enough to literally just call [wxEntry()](http://docs.wxwidgets.org/trunk/group__group__funcmacro__appinitterm.html#ga7d3eefb35631a5d8dfce97eb17340b21). And you don't need to use `wxThread` for this thread, actually it's better if you don't. – VZ. Nov 13 '12 at 14:36