Skip to content

Commit

Permalink
Vulkan: Avoid race in compile thread exit.
Browse files Browse the repository at this point in the history
  • Loading branch information
unknownbrackets committed Jan 1, 2023
1 parent d65c7fb commit e97c88f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Common/GPU/Vulkan/VulkanRenderManager.cpp
Expand Up @@ -294,9 +294,13 @@ void VulkanRenderManager::StopThread() {

INFO_LOG(G3D, "Vulkan submission thread joined. Frame=%d", vulkan_->GetCurFrame());

compileCond_.notify_all();
compileThread_.join();
INFO_LOG(G3D, "Vulkan compiler thread joined.");
if (compileThread_.joinable()) {
// Lock to avoid race conditions.
std::lock_guard<std::mutex> guard(compileMutex_);
compileCond_.notify_all();
compileThread_.join();
INFO_LOG(G3D, "Vulkan compiler thread joined.");
}

// Eat whatever has been queued up for this frame if anything.
Wipe();
Expand Down Expand Up @@ -352,7 +356,7 @@ void VulkanRenderManager::CompileThreadFunc() {
std::vector<CompileQueueEntry> toCompile;
{
std::unique_lock<std::mutex> lock(compileMutex_);
if (compileQueue_.empty()) {
if (compileQueue_.empty() && run_) {
compileCond_.wait(lock);
}
toCompile = std::move(compileQueue_);
Expand Down

0 comments on commit e97c88f

Please sign in to comment.