assert (joinable) before joining threads.
[dcpomatic.git] / src / lib / server.cc
index f9f91417848bd010112ffb4d1abee49089a63ec5..dd076a049cd01b62cc08c47d51ee90b62a8d2db6 100644 (file)
@@ -78,17 +78,22 @@ Server::~Server ()
                boost::mutex::scoped_lock lm (_worker_mutex);
                _terminate = true;
                _empty_condition.notify_all ();
+               _full_condition.notify_all ();
        }
 
-       for (vector<boost::thread*>::iterator i = _worker_threads.begin(); i != _worker_threads.end(); ++i) {
-               (*i)->join ();
-               delete *i;
+       BOOST_FOREACH (boost::thread* i, _worker_threads) {
+               DCPOMATIC_ASSERT (i->joinable ());
+               i->join ();
+               delete i;
        }
 
        _io_service.stop ();
 
        _broadcast.io_service.stop ();
-       _broadcast.thread->join ();
+       if (_broadcast.thread) {
+               DCPOMATIC_ASSERT (_broadcast.thread->join ());
+               _broadcast.thread->join ();
+       }
 }
 
 /** @param after_read Filled in with gettimeofday() after reading the input from the network.