Be a bit safer with ThreadedStaticText.
authorCarl Hetherington <cth@carlh.net>
Sat, 22 Sep 2012 12:44:32 +0000 (13:44 +0100)
committerCarl Hetherington <cth@carlh.net>
Sat, 22 Sep 2012 12:44:32 +0000 (13:44 +0100)
src/wx/wx_util.cc
src/wx/wx_util.h

index 5a9986215585b6f0a8266f26c7faa1fcba0e5bc0..712e235700b5776a5dc18bedba260775795bed0a 100644 (file)
@@ -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
index 555a3ab0ee84344b5c2a16a1d990a4154751ce47..3a454c7c4f3cbd4d7d8cd205a48b8689a3d45496 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <wx/wx.h>
 #include <boost/function.hpp>
+#include <boost/thread.hpp>
 
 /** @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<std::string ()> fn);
+       ~ThreadedStaticText ();
 
 private:
        void run (boost::function<std::string ()> fn);
        void thread_finished (wxCommandEvent& ev);
 
+       boost::thread* _thread;
+       
        static const int _update_event_id;
 };