From f39655c0c8670b5be9ae95ad67a981edfe68ceda Mon Sep 17 00:00:00 2001 From: German Date: Fri, 6 Jan 2023 15:18:26 -0500 Subject: [PATCH] SWDEV-372757 - Don't destroy null queue in MT Skip destruction of the null queue for MT. Windows can destroy worker thread on exit during the stream destruction, causing a race condition. Change-Id: I3e4bc3ab2b477d38c0aec1fc59e6f1af0f8f6b0f --- hipamd/src/hip_internal.hpp | 2 +- hipamd/src/hip_stream.cpp | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/hipamd/src/hip_internal.hpp b/hipamd/src/hip_internal.hpp index 603390f96c..b507b3b4a6 100644 --- a/hipamd/src/hip_internal.hpp +++ b/hipamd/src/hip_internal.hpp @@ -406,7 +406,7 @@ namespace hip { Device(amd::Context* ctx, int devId): context_(ctx), deviceId_(devId), null_stream_(this, Stream::Priority::Normal, 0, true), - flags_(hipDeviceScheduleSpin), + flags_(hipDeviceScheduleSpin), isActive_(false), default_mem_pool_(nullptr), current_mem_pool_(nullptr) diff --git a/hipamd/src/hip_stream.cpp b/hipamd/src/hip_stream.cpp index 9f6a12bf3a..bd1282e9f8 100644 --- a/hipamd/src/hip_stream.cpp +++ b/hipamd/src/hip_stream.cpp @@ -48,8 +48,12 @@ Stream::~Stream() { amd::ScopedLock lock(streamSetLock); streamSet.erase(this); - queue_->release(); - queue_ = nullptr; + // Skip queue destruction for null stream in MT. Queue worker thread can be destroyed on + // the app exit, during the stream destruction, causing a race condition. + if (!null_ || AMD_DIRECT_DISPATCH) { + queue_->release(); + queue_ = nullptr; + } } }