diff --git a/sycl/source/detail/event_impl.cpp b/sycl/source/detail/event_impl.cpp index 398e0cc7bdc9a..77058b5040a59 100644 --- a/sycl/source/detail/event_impl.cpp +++ b/sycl/source/detail/event_impl.cpp @@ -114,8 +114,9 @@ void event_impl::wait_and_throw( if (Cmd) Cmd->getQueue()->throw_asynchronous(); } - if (MQueue) - MQueue->throw_asynchronous(); + QueueImplPtr Queue = MQueue.lock(); + if (Queue) + Queue->throw_asynchronous(); } template <> diff --git a/sycl/source/detail/event_impl.hpp b/sycl/source/detail/event_impl.hpp index b9c8d4fa17de5..2593ad762dfb8 100644 --- a/sycl/source/detail/event_impl.hpp +++ b/sycl/source/detail/event_impl.hpp @@ -25,6 +25,7 @@ class context_impl; using ContextImplPtr = std::shared_ptr; class queue_impl; using QueueImplPtr = std::shared_ptr; +using QueueImplWPtr = std::weak_ptr; class event_impl { public: @@ -147,7 +148,7 @@ class event_impl { private: RT::PiEvent MEvent = nullptr; ContextImplPtr MContext; - QueueImplPtr MQueue; + QueueImplWPtr MQueue; bool MOpenCLInterop = false; bool MHostEvent = true; std::unique_ptr MHostProfilingInfo;