+ auto work = make_shared<boost::asio::io_service::work>(service);
+
+ int const threads = max (1, Config::instance()->master_encoding_threads());
+
+ for (int i = 0; i < threads; ++i) {
+ pool.create_thread (boost::bind (&boost::asio::io_service::run, &service));
+ }
+
+ std::function<void (float)> set_progress;
+ if (job) {
+ set_progress = boost::bind (&Writer::set_digest_progress, this, job.get(), _1);
+ } else {
+ set_progress = [](float) {
+ boost::this_thread::interruption_point();
+ };
+ }
+
+ for (auto& i: _reels) {
+ service.post (boost::bind (&ReelWriter::calculate_digests, &i, set_progress));
+ }
+ service.post (boost::bind (&Writer::calculate_referenced_digests, this, set_progress));
+
+ work.reset ();
+
+ try {
+ pool.join_all ();
+ } catch (boost::thread_interrupted) {
+ /* join_all was interrupted, so we need to interrupt the threads
+ * in our pool then try again to join them.
+ */
+ pool.interrupt_all ();
+ pool.join_all ();
+ }
+
+ service.stop ();
+}
+
+
+/** @param output_dcp Path to DCP folder to write */
+void
+Writer::finish (boost::filesystem::path output_dcp)
+{
+ if (_thread.joinable()) {
+ LOG_GENERAL_NC ("Terminating writer thread");
+ terminate_thread (true);
+ }