From 8fca1fbb28aec5d4db4a4ced2ab14be55c10d27d Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 1 Sep 2015 21:07:21 +0100 Subject: Don't start thread in constructor. (ServerFinder) --- src/lib/server_finder.cc | 16 +++++++++++++--- src/lib/server_finder.h | 2 ++ 2 files changed, 15 insertions(+), 3 deletions(-) (limited to 'src/lib') 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 @@ -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; 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 (); -- cgit v1.2.3