Fix threading bug in CovarianceImpl.

This change fixes a bug in ceres::CovarianceImpl where a new thread was always being created even when num_threads=1. After this fix, when num_threads=1, CovarianceImpl should run single-threaded and will not create any additional threads.

Change-Id: I784e359f8afe3e7e6d72930500a10e909bfe9308
diff --git a/internal/ceres/covariance_impl.cc b/internal/ceres/covariance_impl.cc
index 8da6d89..5622194 100644
--- a/internal/ceres/covariance_impl.cc
+++ b/internal/ceres/covariance_impl.cc
@@ -319,7 +319,7 @@
   // Technically the following code is a double nested loop where
   // i = 1:n, j = i:n.
   int iteration_count = (num_parameters * (num_parameters + 1)) / 2;
-  problem_->context()->EnsureMinimumThreads(num_threads);
+  problem_->context()->EnsureMinimumThreads(num_threads - 1);
   ParallelFor(problem_->context(),
               0,
               iteration_count,
@@ -668,7 +668,7 @@
   const int num_threads = options_.num_threads;
   auto workspace = std::make_unique<double[]>(num_threads * num_cols);
 
-  problem_->context()->EnsureMinimumThreads(num_threads);
+  problem_->context()->EnsureMinimumThreads(num_threads - 1);
   ParallelFor(
       problem_->context(), 0, num_cols, num_threads, [&](int thread_id, int r) {
         const int row_begin = rows[r];
@@ -859,7 +859,7 @@
   const int num_threads = options_.num_threads;
   auto workspace = std::make_unique<double[]>(num_threads * num_cols);
 
-  problem_->context()->EnsureMinimumThreads(num_threads);
+  problem_->context()->EnsureMinimumThreads(num_threads - 1);
   ParallelFor(
       problem_->context(), 0, num_cols, num_threads, [&](int thread_id, int r) {
         const int row_begin = rows[r];