From 01be9b7292d7763e2e8e2ae1016bd2539d5bb083 Mon Sep 17 00:00:00 2001 From: Hao Lu Date: Fri, 21 Dec 2018 15:05:12 -0800 Subject: [PATCH] Handling nullptr case 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 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/caffe2/utils/threadpool/pthreadpool_impl.cc b/caffe2/utils/threadpool/pthreadpool_impl.cc index 41cc3c0..2709e87 100644 --- a/caffe2/utils/threadpool/pthreadpool_impl.cc +++ b/caffe2/utils/threadpool/pthreadpool_impl.cc @@ -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(threadpool) ->run( [function, argument](int threadId, size_t workId) { -- 2.7.4