diff options
| author | Carl Hetherington <cth@carlh.net> | 2015-09-01 21:07:21 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2015-09-01 21:07:21 +0100 |
| commit | 8fca1fbb28aec5d4db4a4ced2ab14be55c10d27d (patch) | |
| tree | 2f8dd376cc49d09e5633db82a8d19685a163f7a3 | |
| parent | cefba53fe130807e96e608ad3bbb87786b654c6e (diff) | |
Don't start thread in constructor. (ServerFinder)
| -rw-r--r-- | src/lib/server_finder.cc | 16 | ||||
| -rw-r--r-- | src/lib/server_finder.h | 2 |
2 files changed, 15 insertions, 3 deletions
diff --git a/src/lib/server_finder.cc b/src/lib/server_finder.cc index 315d8d79d..3683d7bd0 100644 --- a/src/lib/server_finder.cc +++ b/src/lib/server_finder.cc @@ -46,9 +46,14 @@ ServerFinder::ServerFinder () , _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; diff --git a/src/lib/server_finder.h b/src/lib/server_finder.h index 8e643de79..8aa07c069 100644 --- a/src/lib/server_finder.h +++ b/src/lib/server_finder.h @@ -53,6 +53,8 @@ private: ServerFinder (); ~ServerFinder (); + void start (); + void search_thread (); void listen_thread (); |
