File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -141,16 +141,25 @@ void SYCLMemObjT::updateHostMemory(void *const Ptr) {
141141}
142142
143143void SYCLMemObjT::updateHostMemory () {
144- if ((MUploadDataFunctor != nullptr ) && MNeedWriteBack)
144+ // Don't try updating host memory when shutting down.
145+ if ((MUploadDataFunctor != nullptr ) && MNeedWriteBack &&
146+ GlobalHandler::instance ().isOkToDefer ())
145147 MUploadDataFunctor ();
146148
147149 // If we're attached to a memory record, process the deletion of the memory
148150 // record. We may get detached before we do this.
149151 if (MRecord) {
150- bool Result = Scheduler::getInstance ().removeMemoryObject (this );
152+ // Don't strictly try holding the lock in removeMemoryObject during shutdown
153+ // to prevent deadlocks.
154+ bool Result = Scheduler::getInstance ().removeMemoryObject (
155+ this , GlobalHandler::instance ().isOkToDefer ());
151156 std::ignore = Result; // for no assert build
157+
158+ // removeMemoryObject might fail during shutdown because of not being
159+ // able to hold write lock. This can happen if shutdown happens due to
160+ // exception/termination while holding lock.
152161 assert (
153- Result &&
162+ ( Result || ! GlobalHandler::instance (). isOkToDefer ()) &&
154163 " removeMemoryObject should not return false in mem object destructor" );
155164 }
156165 releaseHostMem (MShadowCopy);
You can’t perform that action at this time.
0 commit comments