@@ -66,7 +66,9 @@ EventImplPtr Scheduler::addCG(std::unique_ptr<detail::CG> CommandGroup,
66
66
Command *NewCmd = nullptr ;
67
67
const bool IsKernel = CommandGroup->getType () == CG::KERNEL;
68
68
{
69
- std::lock_guard<std::shared_timed_mutex> Lock (MGraphLock);
69
+ std::unique_lock<std::shared_timed_mutex> Lock (MGraphLock, std::defer_lock);
70
+ while (!Lock.try_lock ())
71
+ ;
70
72
71
73
switch (CommandGroup->getType ()) {
72
74
case CG::UPDATE_HOST:
@@ -91,7 +93,9 @@ EventImplPtr Scheduler::addCG(std::unique_ptr<detail::CG> CommandGroup,
91
93
}
92
94
93
95
EventImplPtr Scheduler::addCopyBack (Requirement *Req) {
94
- std::lock_guard<std::shared_timed_mutex> Lock (MGraphLock);
96
+ std::unique_lock<std::shared_timed_mutex> Lock (MGraphLock, std::defer_lock);
97
+ while (!Lock.try_lock ())
98
+ ;
95
99
Command *NewCmd = MGraphBuilder.addCopyBack (Req);
96
100
// Command was not creted because there were no operations with
97
101
// buffer.
@@ -147,7 +151,9 @@ void Scheduler::cleanupFinishedCommands(EventImplPtr FinishedEvent) {
147
151
}
148
152
149
153
void Scheduler::removeMemoryObject (detail::SYCLMemObjI *MemObj) {
150
- std::lock_guard<std::shared_timed_mutex> Lock (MGraphLock);
154
+ std::unique_lock<std::shared_timed_mutex> Lock (MGraphLock, std::defer_lock);
155
+ while (!Lock.try_lock ())
156
+ ;
151
157
152
158
MemObjRecord *Record = MGraphBuilder.getMemObjRecord (MemObj);
153
159
if (!Record)
@@ -161,7 +167,13 @@ void Scheduler::removeMemoryObject(detail::SYCLMemObjI *MemObj) {
161
167
162
168
EventImplPtr Scheduler::addHostAccessor (Requirement *Req,
163
169
const bool destructor) {
164
- std::lock_guard<std::shared_timed_mutex> Lock (MGraphLock);
170
+ // Avoiding deadlock situation for MSVC. std::shared_timed_mutex specification
171
+ // does not specify a priority for shared and exclusive locks. It will be a
172
+ // deadlock in MSVC's std::shared_timed_mutex implementation, if exclusive
173
+ // lock occurs after shared lock.
174
+ std::unique_lock<std::shared_timed_mutex> Lock (MGraphLock, std::defer_lock);
175
+ while (!Lock.try_lock ())
176
+ ;
165
177
166
178
Command *NewCmd = MGraphBuilder.addHostAccessor (Req, destructor);
167
179
0 commit comments