Skip to content

Commit 892ecba

Browse files
authored
[SYCL] Fix hang in conditional variable pattern in program manager (#2493)
Signed-off-by: Alexander Flegontov <[email protected]>
1 parent 6242160 commit 892ecba

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,12 @@ getOrBuild(KernelProgramCache &KPCache, KeyT &&CacheKey, AcquireFT &&Acquire,
195195
BuildResult->Ptr.store(Desired);
196196
#endif
197197

198-
BuildResult->State.store(BS_Done);
198+
{
199+
// Even if shared variable is atomic, it must be modified under the mutex
200+
// in order to correctly publish the modification to the waiting thread
201+
std::lock_guard<std::mutex> Lock(BuildResult->MBuildResultMutex);
202+
BuildResult->State.store(BS_Done);
203+
}
199204

200205
KPCache.notifyAllBuild(*BuildResult);
201206

@@ -204,13 +209,19 @@ getOrBuild(KernelProgramCache &KPCache, KeyT &&CacheKey, AcquireFT &&Acquire,
204209
BuildResult->Error.Msg = Ex.what();
205210
BuildResult->Error.Code = Ex.get_cl_code();
206211

207-
BuildResult->State.store(BS_Failed);
212+
{
213+
std::lock_guard<std::mutex> Lock(BuildResult->MBuildResultMutex);
214+
BuildResult->State.store(BS_Failed);
215+
}
208216

209217
KPCache.notifyAllBuild(*BuildResult);
210218

211219
std::rethrow_exception(std::current_exception());
212220
} catch (...) {
213-
BuildResult->State.store(BS_Failed);
221+
{
222+
std::lock_guard<std::mutex> Lock(BuildResult->MBuildResultMutex);
223+
BuildResult->State.store(BS_Failed);
224+
}
214225

215226
KPCache.notifyAllBuild(*BuildResult);
216227

0 commit comments

Comments
 (0)