Don't start thread in constructor. (ServerFinder)
authorCarl Hetherington <cth@carlh.net>
Tue, 1 Sep 2015 20:07:21 +0000 (21:07 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 1 Sep 2015 20:07:21 +0000 (21:07 +0100)
src/lib/server_finder.cc
src/lib/server_finder.h

index 315d8d79dadc00b5d8cb87363b8a2e59b3929c0d..3683d7bd0add8db1a8333b110a72a5ff5141df0e 100644 (file)
@@ -45,10 +45,15 @@ ServerFinder::ServerFinder ()
        , _search_thread (0)
        , _listen_thread (0)
        , _stop (false)
+{
+       Config::instance()->Changed.connect (boost::bind (&ServerFinder::config_changed, this, _1));
+}
+
+void
+ServerFinder::start ()
 {
        _search_thread = new boost::thread (boost::bind (&ServerFinder::search_thread, this));
        _listen_thread = new boost::thread (boost::bind (&ServerFinder::listen_thread, this));
-       Config::instance()->Changed.connect (boost::bind (&ServerFinder::config_changed, this, _1));
 }
 
 ServerFinder::~ServerFinder ()
@@ -56,10 +61,14 @@ ServerFinder::~ServerFinder ()
        _stop = true;
 
        _search_condition.notify_all ();
-       _search_thread->join ();
+       if (_search_thread) {
+               _search_thread->join ();
+       }
 
        _listen_io_service.stop ();
-       _listen_thread->join ();
+       if (_listen_thread) {
+               _listen_thread->join ();
+       }
 }
 
 void
@@ -194,6 +203,7 @@ ServerFinder::instance ()
 {
        if (!_instance) {
                _instance = new ServerFinder ();
+               _instance->start ();
        }
 
        return _instance;
index 8e643de79d96c909f469987afcace83615af1009..8aa07c0696145918cc64f5a8cc09fb35f98cbbb3 100644 (file)
@@ -53,6 +53,8 @@ private:
        ServerFinder ();
        ~ServerFinder ();
 
+       void start ();
+
        void search_thread ();
        void listen_thread ();