From 36eade7f4ccf5a7da8e9f5e7ec32d2e4f8660e85 Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Wed, 26 Aug 2020 01:45:51 +0000 Subject: hle/kernel: Fix data race in GetCurrentHostThreadID As reported by tsan, host_thread_ids could be read while any of the RegisterHostThread variants were called. To fix this, lock the register mutex when yuzu is running in multicore mode and GetCurrentHostThreadID is called. --- src/core/hle/kernel/kernel.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index cabe8d418..f2b0fe2fd 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp @@ -219,6 +219,7 @@ struct KernelCore::Impl { return static_cast(system.GetCpuManager().CurrentCore()); } } + std::unique_lock lock{register_thread_mutex}; const auto it = host_thread_ids.find(this_id); if (it == host_thread_ids.end()) { return Core::INVALID_HOST_THREAD_ID; @@ -324,7 +325,7 @@ struct KernelCore::Impl { std::unordered_map host_thread_ids; u32 registered_thread_ids{Core::Hardware::NUM_CPU_CORES}; std::bitset registered_core_threads; - std::mutex register_thread_mutex; + mutable std::mutex register_thread_mutex; // Kernel memory management std::unique_ptr memory_manager; -- cgit v1.2.3