File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -164,7 +164,19 @@ class ExecSingleton
164164 {
165165 std::lock_guard<std::mutex> lock (mutex_);
166166 if (!instance_)
167- create (0 );
167+ {
168+ // Initialize with default thread count if instance is null
169+ uint32_t numThreads = std::thread::hardware_concurrency () + 1 ;
170+ numThreads_ = numThreads;
171+ if (numThreads > 1 )
172+ {
173+ instance_ = std::make_unique<tf::Executor>(numThreads - 1 );
174+ }
175+ }
176+ if (!instance_)
177+ {
178+ throw std::runtime_error (" Executor not initialized (single-threaded mode)" );
179+ }
168180 return *instance_;
169181 }
170182
@@ -175,6 +187,7 @@ class ExecSingleton
175187 */
176188 static size_t num_threads ()
177189 {
190+ std::lock_guard<std::mutex> lock (mutex_);
178191 return numThreads_;
179192 }
180193
@@ -223,4 +236,4 @@ class ExecSingleton
223236 *
224237 */
225238 static size_t numThreads_;
226- };
239+ };
You can’t perform that action at this time.
0 commit comments