From: Hao Lu Date: Fri, 21 Dec 2018 23:05:12 +0000 (-0800) Subject: Handling nullptr case X-Git-Tag: accepted/tizen/6.5/unified/20211028.231830~2113 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=01be9b7292d7763e2e8e2ae1016bd2539d5bb083;p=platform%2Fupstream%2Fpytorch.git Handling nullptr case Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/15467 Reviewed By: Maratyszcza Differential Revision: D13536504 fbshipit-source-id: ab46ff6bb4b6ce881c3e29d7e6a095ea62289db4 --- 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) {