C++: Thread sanitizer reports issues
One example:
Backtrace
WARNING: ThreadSanitizer: unlock of an unlocked mutex (or by a wrong thread) (pid=40261)
#0 pthread_mutex_unlock <null> (test_satellite_base+0x7aa0f) (BuildId: 3dccb6de49ddf980bdb0b1ec6431d5ef6b521187)
#1 __gthread_mutex_unlock(pthread_mutex_t*) /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/x86_64-linux-gnu/c++/13/bits/gthr-default.h:779:12 (libConstellationCore.so+0xa9780) (BuildId: 646d0601f4c7293bdec01e2c79e257c06903262a)
#2 std::timed_mutex::unlock() /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/mutex:281:7 (libConstellationCore.so+0xa9780)
#3 std::unique_lock<std::timed_mutex>::unlock() /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/unique_lock.h:200:17 (libConstellationCore.so+0xa9780)
#4 constellation::utils::SubscriberPool<constellation::message::CHP1Message>::loop(std::stop_token const&) /home/stephan/Projects/constellation/build_test/../cxx/constellation/core/subscriber/SubscriberPool.ipp:223:22 (libConstellationCore.so+0xa9780)
#5 void std::__invoke_impl<void, void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*, std::stop_token>(std::__invoke_memfun_deref, void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*&&)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*&&, std::stop_token&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/invoke.h:74:14 (libConstellationCore.so+0xaf4ce) (BuildId: 646d0601f4c7293bdec01e2c79e257c06903262a)
#6 std::__invoke_result<void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*, std::stop_token>::type std::__invoke<void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*, std::stop_token>(void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*&&)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*&&, std::stop_token&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/invoke.h:96:14 (libConstellationCore.so+0xaf4ce)
#7 std::invoke_result<void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*, std::stop_token>::type std::invoke<void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*, std::stop_token>(void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*&&)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*&&, std::stop_token&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/functional:113:14 (libConstellationCore.so+0xaf4ce)
#8 decltype(auto) std::_Bind_front<void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*>::_S_call<std::_Bind_front<void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*>, 0ul, std::stop_token>(std::_Bind_front<void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*>&&, std::integer_sequence<unsigned long, 0ul>, std::stop_token&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/functional:989:11 (libConstellationCore.so+0xaf4ce)
#9 std::invoke_result<void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*, std::stop_token>::type std::_Bind_front<void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*>::operator()<std::stop_token>(std::stop_token&&) && /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/functional:966:11 (libConstellationCore.so+0xaf4ce)
#10 void std::__invoke_impl<void, std::_Bind_front<void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*>, std::stop_token>(std::__invoke_other, std::_Bind_front<void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*>&&, std::stop_token&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/invoke.h:61:14 (libConstellationCore.so+0xaf4ce)
#11 std::__invoke_result<std::_Bind_front<void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*>, std::stop_token>::type std::__invoke<std::_Bind_front<void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*>, std::stop_token>(std::_Bind_front<void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*>&&, std::stop_token&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/invoke.h:96:14 (libConstellationCore.so+0xaf4ce)
#12 void std::thread::_Invoker<std::tuple<std::_Bind_front<void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*>, std::stop_token>>::_M_invoke<0ul, 1ul>(std::_Index_tuple<0ul, 1ul>) /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/std_thread.h:292:13 (libConstellationCore.so+0xaf4ce)
#13 std::thread::_Invoker<std::tuple<std::_Bind_front<void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*>, std::stop_token>>::operator()() /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/std_thread.h:299:11 (libConstellationCore.so+0xaf4ce)
#14 std::thread::_State_impl<std::thread::_Invoker<std::tuple<std::_Bind_front<void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*>, std::stop_token>>>::_M_run() /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/std_thread.h:244:13 (libConstellationCore.so+0xaf4ce)
#15 <null> <null> (libstdc++.so.6+0xe0f23) (BuildId: 38d93d32a2f93382c6169e53c957922363dbb687)
Location is stack of main thread.
Location is global '??' at 0x7ffffffde000 ([stack]+0x1f618)
Mutex M0 (0x7fffffffd618) created at:
#0 pthread_mutex_unlock <null> (test_satellite_base+0x7aa0f) (BuildId: 3dccb6de49ddf980bdb0b1ec6431d5ef6b521187)
#1 __gthread_mutex_unlock(pthread_mutex_t*) /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/x86_64-linux-gnu/c++/13/bits/gthr-default.h:779:12 (libConstellationCore.so+0xa9780) (BuildId: 646d0601f4c7293bdec01e2c79e257c06903262a)
#2 std::timed_mutex::unlock() /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/mutex:281:7 (libConstellationCore.so+0xa9780)
#3 std::unique_lock<std::timed_mutex>::unlock() /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/unique_lock.h:200:17 (libConstellationCore.so+0xa9780)
#4 constellation::utils::SubscriberPool<constellation::message::CHP1Message>::loop(std::stop_token const&) /home/stephan/Projects/constellation/build_test/../cxx/constellation/core/subscriber/SubscriberPool.ipp:223:22 (libConstellationCore.so+0xa9780)
#5 void std::__invoke_impl<void, void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*, std::stop_token>(std::__invoke_memfun_deref, void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*&&)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*&&, std::stop_token&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/invoke.h:74:14 (libConstellationCore.so+0xaf4ce) (BuildId: 646d0601f4c7293bdec01e2c79e257c06903262a)
#6 std::__invoke_result<void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*, std::stop_token>::type std::__invoke<void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*, std::stop_token>(void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*&&)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*&&, std::stop_token&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/invoke.h:96:14 (libConstellationCore.so+0xaf4ce)
#7 std::invoke_result<void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*, std::stop_token>::type std::invoke<void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*, std::stop_token>(void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*&&)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*&&, std::stop_token&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/functional:113:14 (libConstellationCore.so+0xaf4ce)
#8 decltype(auto) std::_Bind_front<void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*>::_S_call<std::_Bind_front<void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*>, 0ul, std::stop_token>(std::_Bind_front<void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*>&&, std::integer_sequence<unsigned long, 0ul>, std::stop_token&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/functional:989:11 (libConstellationCore.so+0xaf4ce)
#9 std::invoke_result<void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*, std::stop_token>::type std::_Bind_front<void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*>::operator()<std::stop_token>(std::stop_token&&) && /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/functional:966:11 (libConstellationCore.so+0xaf4ce)
#10 void std::__invoke_impl<void, std::_Bind_front<void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*>, std::stop_token>(std::__invoke_other, std::_Bind_front<void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*>&&, std::stop_token&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/invoke.h:61:14 (libConstellationCore.so+0xaf4ce)
#11 std::__invoke_result<std::_Bind_front<void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*>, std::stop_token>::type std::__invoke<std::_Bind_front<void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*>, std::stop_token>(std::_Bind_front<void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*>&&, std::stop_token&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/invoke.h:96:14 (libConstellationCore.so+0xaf4ce)
#12 void std::thread::_Invoker<std::tuple<std::_Bind_front<void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*>, std::stop_token>>::_M_invoke<0ul, 1ul>(std::_Index_tuple<0ul, 1ul>) /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/std_thread.h:292:13 (libConstellationCore.so+0xaf4ce)
#13 std::thread::_Invoker<std::tuple<std::_Bind_front<void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*>, std::stop_token>>::operator()() /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/std_thread.h:299:11 (libConstellationCore.so+0xaf4ce)
#14 std::thread::_State_impl<std::thread::_Invoker<std::tuple<std::_Bind_front<void (constellation::utils::SubscriberPool<constellation::message::CHP1Message>::*)(std::stop_token const&), constellation::utils::SubscriberPool<constellation::message::CHP1Message>*>, std::stop_token>>>::_M_run() /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/std_thread.h:244:13 (libConstellationCore.so+0xaf4ce)
#15 <null> <null> (libstdc++.so.6+0xe0f23) (BuildId: 38d93d32a2f93382c6169e53c957922363dbb687)
SUMMARY: ThreadSanitizer: unlock of an unlocked mutex (or by a wrong thread) (/home/stephan/Projects/constellation/build_test/cxx/tests/test_satellite_base+0x7aa0f) (BuildId: 3dccb6de49ddf980bdb0b1ec6431d5ef6b521187) in __interceptor_pthread_mutex_unlock
To test:
CXX="ccache clang++" meson setup build_tsan -Dbuildtype=debugoptimized -Db_sanitize=thread -Db_lundef=false
Hint: run the tests manually since they might time out
Edited by Stephan Lachnit