From 90076a4c442070b268072b076937630d0b4313dc Mon Sep 17 00:00:00 2001 From: "Agarwal, Udit" Date: Thu, 20 Nov 2025 19:29:31 +0100 Subject: [PATCH 1/2] [SYCL] Prevent deadlock during shutdown by not holding GraphUpdate mutex --- sycl/source/detail/sycl_mem_obj_t.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/sycl/source/detail/sycl_mem_obj_t.cpp b/sycl/source/detail/sycl_mem_obj_t.cpp index 46f7305a11cc7..f9410aa750f09 100644 --- a/sycl/source/detail/sycl_mem_obj_t.cpp +++ b/sycl/source/detail/sycl_mem_obj_t.cpp @@ -141,16 +141,25 @@ void SYCLMemObjT::updateHostMemory(void *const Ptr) { } void SYCLMemObjT::updateHostMemory() { - if ((MUploadDataFunctor != nullptr) && MNeedWriteBack) + // Don't try updating host memory when stutting down. + if ((MUploadDataFunctor != nullptr) && MNeedWriteBack && + GlobalHandler::instance().isOkToDefer()) MUploadDataFunctor(); // If we're attached to a memory record, process the deletion of the memory // record. We may get detached before we do this. if (MRecord) { - bool Result = Scheduler::getInstance().removeMemoryObject(this); + // Don't strictly try holding the lock in removeMemoryObject during shutdown + // to prevent deadlocks. + bool Result = Scheduler::getInstance().removeMemoryObject( + this, GlobalHandler::instance().isOkToDefer()); std::ignore = Result; // for no assert build + + // removeMemoryObject might fail during shutdown because of not being + // able to hold write lock. This can happen if shutdown happen due to + // exception/termination while holding lock. assert( - Result && + (Result || !GlobalHandler::instance().isOkToDefer()) && "removeMemoryObject should not return false in mem object destructor"); } releaseHostMem(MShadowCopy); From 747e3266845408dae1a067f972e2751dc32c3096 Mon Sep 17 00:00:00 2001 From: Udit Kumar Agarwal Date: Mon, 24 Nov 2025 15:08:16 +0530 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- sycl/source/detail/sycl_mem_obj_t.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sycl/source/detail/sycl_mem_obj_t.cpp b/sycl/source/detail/sycl_mem_obj_t.cpp index f9410aa750f09..bae53031930de 100644 --- a/sycl/source/detail/sycl_mem_obj_t.cpp +++ b/sycl/source/detail/sycl_mem_obj_t.cpp @@ -141,7 +141,7 @@ void SYCLMemObjT::updateHostMemory(void *const Ptr) { } void SYCLMemObjT::updateHostMemory() { - // Don't try updating host memory when stutting down. + // Don't try updating host memory when shutting down. if ((MUploadDataFunctor != nullptr) && MNeedWriteBack && GlobalHandler::instance().isOkToDefer()) MUploadDataFunctor(); @@ -156,7 +156,7 @@ void SYCLMemObjT::updateHostMemory() { std::ignore = Result; // for no assert build // removeMemoryObject might fail during shutdown because of not being - // able to hold write lock. This can happen if shutdown happen due to + // able to hold write lock. This can happen if shutdown happens due to // exception/termination while holding lock. assert( (Result || !GlobalHandler::instance().isOkToDefer()) &&