+ terminate_threads ();
+
+ /* XXX: could re-use threads */
+
+ boost::mutex::scoped_lock lm (_threads_mutex);
+
+ if (!Config::instance()->only_servers_encode ()) {
+ for (int i = 0; i < Config::instance()->num_local_encoding_threads (); ++i) {
+ _threads.push_back (new boost::thread (boost::bind (&Encoder::encoder_thread, this, optional<ServerDescription> ())));
+ }
+ }
+
+ BOOST_FOREACH (ServerDescription i, ServerFinder::instance()->servers ()) {
+ LOG_GENERAL (N_("Adding %1 worker threads for remote %2"), i.threads(), i.host_name ());
+ for (int j = 0; j < i.threads(); ++j) {
+ _threads.push_back (new boost::thread (boost::bind (&Encoder::encoder_thread, this, i)));
+ }
+ }
+
+ _writer->set_encoder_threads (_threads.size ());