Skip to content

Commit 1b70ce6

Browse files
committed
make __copy__ methods in cache classes hold locks
1 parent ebf970f commit 1b70ce6

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

dpctl/_sycl_device_factory.pyx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,9 @@ cdef class _DefaultDeviceCache:
445445
def __copy__(self):
446446
cdef _DefaultDeviceCache _copy = _DefaultDeviceCache.__new__(
447447
_DefaultDeviceCache)
448-
_copy._update_map(self.__device_map__)
448+
# lock must be held to avoid race conditions on map state
449+
with self._cache_lock:
450+
_copy._update_map(self.__device_map__.copy())
449451
return _copy
450452

451453

dpctl/_sycl_queue_manager.pyx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ cdef class _DeviceDefaultQueueCache:
7373
cdef _DeviceDefaultQueueCache _copy = _DeviceDefaultQueueCache.__new__(
7474
_DeviceDefaultQueueCache
7575
)
76-
_copy._update_map(self.__device_queue_map__)
76+
# lock must be held to avoid race conditions on map state
77+
with self._cache_lock:
78+
_copy._update_map(self.__device_queue_map__.copy())
7779
return _copy
7880

7981

0 commit comments

Comments
 (0)