+ 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 (int, int64_t, int64_t)> set_progress;
+ if (job) {
+ set_progress = boost::bind(&Writer::set_digest_progress, this, job.get(), _1, _2, _3);
+ } else {
+ set_progress = [](int, int64_t, int64_t) {
+ boost::this_thread::interruption_point();
+ };
+ }
+
+ int index = 0;
+
+ for (auto& i: _reels) {
+ service.post(
+ boost::bind(
+ &ReelWriter::calculate_digests,
+ &i,
+ std::function<void (int64_t, int64_t)>(boost::bind(set_progress, index, _1, _2))
+ ));
+ ++index;
+ }
+ service.post(
+ boost::bind(
+ &Writer::calculate_referenced_digests,
+ this,
+ std::function<void (int64_t, int64_t)>(boost::bind(set_progress, index, _1, _2))
+ ));
+
+ 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);
+ }