Skip to content

Commit 8445019

Browse files
author
Grok Compression
committed
ExecSingleton: fix race between create and get
1 parent d3c7a30 commit 8445019

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/lib/core/scheduling/ExecSingleton.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff 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+
};

0 commit comments

Comments
 (0)