wxWidgets multithreaded app crashes

Hello,
I need to inplement a very simple multithreading in my app. I know how to start and run a thread but when I check whether thread is alive, and if the therad has exited, the app crashes.

Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class TestThread: public wxThread
{
public:
  void *Entry()
  {
     // do something
  }
};


void wx_thread_testFrame::OnAbout(wxCommandEvent& event)
{
    wxThread *test=new TestThread;
    test->Create();
    test->Run();

    wxMessageBox("Thread started", "i");

    if(test->IsAlive()) // if thread is still running, everything works fine
      {
         wxMessageBox("Click ok to kill the thread", "i");
         test->Delete();
      }
    else // if thread has exited, IsAlive crashes the program
      {
         wxMessageBox("Thread ia not running", "i");
      }
}

Anyone knows how can I fix this?

Thanks for help.
Instead, when worker thread exits, make it post an event to main thread. This is common to multi-threading programming in general, not just wxwidgets.
May be you are deleting the thread which is currently running or locked ?
You might be using exit instead delete.

And you should also wait for some time to let your thread finish it's work.

don't you think it is bad to delete thread just after you started using run() ? may be more detail can help like wht you do in run ?
Topic archived. No new replies allowed.