From 21b2cd0a6e34be7590fef11af91fd47985bf970c Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sat, 22 Sep 2012 13:44:32 +0100 Subject: Be a bit safer with ThreadedStaticText. --- src/wx/wx_util.cc | 9 ++++++++- src/wx/wx_util.h | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/wx/wx_util.cc b/src/wx/wx_util.cc index 5a9986215..712e23570 100644 --- a/src/wx/wx_util.cc +++ b/src/wx/wx_util.cc @@ -65,7 +65,14 @@ ThreadedStaticText::ThreadedStaticText (wxWindow* parent, string initial, functi : wxStaticText (parent, wxID_ANY, std_to_wx (initial)) { Connect (_update_event_id, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (ThreadedStaticText::thread_finished), 0, this); - thread t (bind (&ThreadedStaticText::run, this, fn)); + _thread = new thread (bind (&ThreadedStaticText::run, this, fn)); +} + +ThreadedStaticText::~ThreadedStaticText () +{ + /* XXX: this is a bit unfortunate */ + _thread->join (); + delete _thread; } void diff --git a/src/wx/wx_util.h b/src/wx/wx_util.h index 555a3ab0e..3a454c7c4 100644 --- a/src/wx/wx_util.h +++ b/src/wx/wx_util.h @@ -19,6 +19,7 @@ #include #include +#include /** @file src/wx/wx_util.h * @brief Some utility functions and classes. @@ -36,10 +37,13 @@ class ThreadedStaticText : public wxStaticText { public: ThreadedStaticText (wxWindow* parent, std::string initial, boost::function fn); + ~ThreadedStaticText (); private: void run (boost::function fn); void thread_finished (wxCommandEvent& ev); + boost::thread* _thread; + static const int _update_event_id; }; -- cgit v1.2.3