Handling nullptr case
authorHao Lu <hlu@fb.com>
Fri, 21 Dec 2018 23:05:12 +0000 (15:05 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 21 Dec 2018 23:08:00 +0000 (15:08 -0800)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/15467

Reviewed By: Maratyszcza

Differential Revision: D13536504

fbshipit-source-id: ab46ff6bb4b6ce881c3e29d7e6a095ea62289db4

caffe2/utils/threadpool/pthreadpool_impl.cc

index 41cc3c0..2709e87 100644 (file)
@@ -11,6 +11,14 @@ void pthreadpool_compute_1d(
     pthreadpool_function_1d_t function,
     void* argument,
     size_t range) {
+  if (threadpool == nullptr) {
+    /* No thread pool provided: execute function sequentially on the calling
+     * thread */
+    for (size_t i = 0; i < range; i++) {
+      function(argument, i);
+    }
+    return;
+  }
   reinterpret_cast<caffe2::ThreadPool*>(threadpool)
       ->run(
           [function, argument](int threadId, size_t workId) {