From fa1fb2a6b5c0d1050bf5779cbbc86aa0a802d782 Mon Sep 17 00:00:00 2001 From: elsid Date: Sat, 7 Aug 2021 19:29:08 +0200 Subject: [PATCH] Reset mIsReleased before starting threads To fix TSAN warning: WARNING: ThreadSanitizer: data race (pid=68597) Write of size 1 at 0x7b3800079234 by main thread: #0 SceneUtil::WorkQueue::start(unsigned long) /home/elsid/dev/openmw/components/sceneutil/workqueue.cpp:51 (openmw+0x10daa10) #1 SceneUtil::WorkQueue::WorkQueue(unsigned long) /home/elsid/dev/openmw/components/sceneutil/workqueue.cpp:39 (openmw+0x10dad97) #2 OMW::Engine::prepareEngine(Settings::Manager&) /home/elsid/dev/openmw/apps/openmw/engine.cpp:700 (openmw+0xf7cb5a) #3 OMW::Engine::go() /home/elsid/dev/openmw/apps/openmw/engine.cpp:949 (openmw+0xf82688) #4 runApplication(int, char**) /home/elsid/dev/openmw/apps/openmw/main.cpp:316 (openmw+0xf62611) #5 wrapApplication(int (*)(int, char**), int, char**, std::__cxx11::basic_string, std::allocator > const&) /home/elsid/dev/openmw/components/debug/debugging.cpp:205 (openmw+0x125df1c) #6 main /home/elsid/dev/openmw/apps/openmw/main.cpp:328 (openmw+0x596323) Previous read of size 1 at 0x7b3800079234 by thread T10 (mutexes: write M19275778865205896): #0 SceneUtil::WorkQueue::removeWorkItem() /home/elsid/dev/openmw/components/sceneutil/workqueue.cpp:86 (openmw+0x10d9e51) #1 SceneUtil::WorkThread::run() /home/elsid/dev/openmw/components/sceneutil/workqueue.cpp:127 (openmw+0x10da52a) #2 operator() /home/elsid/dev/openmw/components/sceneutil/workqueue.cpp:114 (openmw+0x10da664) #3 __invoke_impl > /usr/include/c++/11.1.0/bits/invoke.h:61 (openmw+0x10da664) #4 __invoke > /usr/include/c++/11.1.0/bits/invoke.h:96 (openmw+0x10da664) #5 _M_invoke<0> /usr/include/c++/11.1.0/bits/std_thread.h:253 (openmw+0x10da664) #6 operator() /usr/include/c++/11.1.0/bits/std_thread.h:260 (openmw+0x10da664) #7 _M_run /usr/include/c++/11.1.0/bits/std_thread.h:211 (openmw+0x10da664) #8 execute_native_thread_routine /build/gcc/src/gcc/libstdc++-v3/src/c++11/thread.cc:82 (libstdc++.so.6+0xd33c3) Location is heap block of size 216 at 0x7b3800079220 allocated by main thread: #0 operator new(unsigned long) /build/gcc/src/gcc/libsanitizer/tsan/tsan_new_delete.cpp:64 (libtsan.so.0+0x91824) #1 OMW::Engine::prepareEngine(Settings::Manager&) /home/elsid/dev/openmw/apps/openmw/engine.cpp:700 (openmw+0xf7cb4c) #2 OMW::Engine::go() /home/elsid/dev/openmw/apps/openmw/engine.cpp:949 (openmw+0xf82688) #3 runApplication(int, char**) /home/elsid/dev/openmw/apps/openmw/main.cpp:316 (openmw+0xf62611) #4 wrapApplication(int (*)(int, char**), int, char**, std::__cxx11::basic_string, std::allocator > const&) /home/elsid/dev/openmw/components/debug/debugging.cpp:205 (openmw+0x125df1c) #5 main /home/elsid/dev/openmw/apps/openmw/main.cpp:328 (openmw+0x596323) Mutex M19275778865205896 is already destroyed. Thread T10 (tid=68609, running) created by main thread at: #0 pthread_create /build/gcc/src/gcc/libsanitizer/tsan/tsan_interceptors_posix.cpp:969 (libtsan.so.0+0x61c3a) #1 std::thread::_M_start_thread(std::unique_ptr >, void (*)()) /build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/x86_64-pc-linux-gnu/bits/gthr-default.h:663 (libstdc++.so.6+0xd36aa) #2 std::_MakeUniq::__single_object std::make_unique(SceneUtil::WorkQueue&) /usr/include/c++/11.1.0/bits/unique_ptr.h:962 (openmw+0x10da987) #3 SceneUtil::WorkQueue::start(unsigned long) /home/elsid/dev/openmw/components/sceneutil/workqueue.cpp:50 (openmw+0x10da987) #4 SceneUtil::WorkQueue::WorkQueue(unsigned long) /home/elsid/dev/openmw/components/sceneutil/workqueue.cpp:39 (openmw+0x10dad97) #5 OMW::Engine::prepareEngine(Settings::Manager&) /home/elsid/dev/openmw/apps/openmw/engine.cpp:700 (openmw+0xf7cb5a) #6 OMW::Engine::go() /home/elsid/dev/openmw/apps/openmw/engine.cpp:949 (openmw+0xf82688) #7 runApplication(int, char**) /home/elsid/dev/openmw/apps/openmw/main.cpp:316 (openmw+0xf62611) #8 wrapApplication(int (*)(int, char**), int, char**, std::__cxx11::basic_string, std::allocator > const&) /home/elsid/dev/openmw/components/debug/debugging.cpp:205 (openmw+0x125df1c) #9 main /home/elsid/dev/openmw/apps/openmw/main.cpp:328 (openmw+0x596323) --- components/sceneutil/workqueue.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/components/sceneutil/workqueue.cpp b/components/sceneutil/workqueue.cpp index 0c68c61921..eb7a7b2cae 100644 --- a/components/sceneutil/workqueue.cpp +++ b/components/sceneutil/workqueue.cpp @@ -46,9 +46,12 @@ WorkQueue::~WorkQueue() void WorkQueue::start(std::size_t workerThreads) { + { + const std::lock_guard lock(mMutex); + mIsReleased = false; + } while (mThreads.size() < workerThreads) mThreads.emplace_back(std::make_unique(*this)); - mIsReleased = false; } void WorkQueue::stop()