Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Threading problem: unlock of an unlocked mutex (or by a wrong thread) #352

Open
sztomi opened this issue Jan 23, 2016 · 1 comment
Open

Comments

@sztomi
Copy link

sztomi commented Jan 23, 2016

I'm using easyloggingpp in a multi-threaded program. I noticed in VS2015 that I was getting an assertion about unlocking an already unlocked mutex. I recompiled on linux with the clang threadsanitizer (-fsanitize=thread) and I got two detailed warnings, one of them being the already unlocked mutex:

WARNING: ThreadSanitizer: unlock of an unlocked mutex (or by a wrong thread) (pid=6101)
    #0 pthread_mutex_unlock /home/sztomi/src/llvm/projects/compiler-rt/lib/tsan/../sanitizer_common/sanitizer_common_interceptors.inc:3340 (callme_test+0x000000555c1f)
    #1 el::base::threading::internal::Mutex::unlock() <null> (callme_test+0x0000006b04bc)
    #2 el::base::threading::internal::ScopedLock<el::base::threading::internal::Mutex>::~ScopedLock() <null> (callme_test+0x00000068a9c2)
    #3 void el::Logger::log<std::string>(el::Level, char const*, std::string const&) <null> (callme_test+0x0000006b0717)
    #4 void el::Logger::debug<std::string>(char const*, std::string const&) <null> (callme_test+0x000000689ccd)
    #5 callme::dispatcher::dispatch(msgpack::v1::object const&) <null> (callme_test+0x0000006ccfe7)
    #6 callme::dispatcher::dispatch(msgpack::v1::sbuffer const&) <null> (callme_test+0x0000006ccdfc)
    #7 void binding_test::raw_call<unsigned char const (&) [23]>(unsigned char const (&) [23]) <null> (callme_test+0x00000064f3f7)
    #8 binding_test_freefunc_void_zeroarg_Test::TestBody() <null> (callme_test+0x000000649af6)
    #9 void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) <null> (callme_test+0x000000633222)
    #10 void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) <null> (callme_test+0x00000060453e)
    #11 testing::Test::Run() <null> (callme_test+0x0000005d6961)
    #12 testing::TestInfo::Run() <null> (callme_test+0x0000005d7934)
    #13 testing::TestCase::Run() <null> (callme_test+0x0000005d8290)
    #14 testing::internal::UnitTestImpl::RunAllTests() <null> (callme_test+0x0000005e2301)
    #15 bool testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) <null> (callme_test+0x0000006394d2)
    #16 bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) <null> (callme_test+0x000000607f54)
    #17 testing::UnitTest::Run() <null> (callme_test+0x0000005e1e1f)
    #18 RUN_ALL_TESTS() <null> (callme_test+0x00000064998d)
    #19 main <null> (callme_test+0x00000064994a)

  Location is heap block of size 632 at 0x7d540000ed80 allocated by main thread:
    #0 operator new(unsigned long) /home/sztomi/src/llvm/projects/compiler-rt/lib/tsan/rtl/tsan_new_delete.cc:45 (callme_test+0x0000005c7213)
    #1 el::base::RegisteredLoggers::get(std::string const&, bool) <null> (callme_test+0x00000068a847)
    #2 el::Loggers::getLogger(std::string const&, bool) <null> (callme_test+0x000000689c35)
    #3 callme::dispatcher::dispatch(msgpack::v1::object const&) <null> (callme_test+0x0000006ccfc4)
    #4 callme::dispatcher::dispatch(msgpack::v1::sbuffer const&) <null> (callme_test+0x0000006ccdfc)
    #5 void binding_test::raw_call<unsigned char const (&) [23]>(unsigned char const (&) [23]) <null> (callme_test+0x00000064f3f7)
    #6 binding_test_freefunc_void_zeroarg_Test::TestBody() <null> (callme_test+0x000000649af6)
    #7 void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) <null> (callme_test+0x000000633222)
    #8 void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) <null> (callme_test+0x00000060453e)
    #9 testing::Test::Run() <null> (callme_test+0x0000005d6961)
    #10 testing::TestInfo::Run() <null> (callme_test+0x0000005d7934)
    #11 testing::TestCase::Run() <null> (callme_test+0x0000005d8290)
    #12 testing::internal::UnitTestImpl::RunAllTests() <null> (callme_test+0x0000005e2301)
    #13 bool testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) <null> (callme_test+0x0000006394d2)
    #14 bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) <null> (callme_test+0x000000607f54)
    #15 testing::UnitTest::Run() <null> (callme_test+0x0000005e1e1f)
    #16 RUN_ALL_TESTS() <null> (callme_test+0x00000064998d)
    #17 main <null> (callme_test+0x00000064994a)

  Mutex M98 (0x7d540000ed90) created at:
    #0 pthread_mutex_init /home/sztomi/src/llvm/projects/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:1179 (callme_test+0x00000054019a)
    #1 el::base::threading::internal::Mutex::Mutex() <null> (callme_test+0x00000068c214)
    #2 el::base::threading::ThreadSafe::ThreadSafe() <null> (callme_test+0x00000068b844)
    #3 el::Logger::Logger(std::string const&, el::Configurations const&, std::map<std::string, std::shared_ptr<std::basic_fstream<char, std::char_traits<char> > >, std::less<std::string>, std::allocator<std::pair<std::string const, std::shared_ptr<std::basic_fstream<char, std::char_traits<char> > > > > >*) <null> (callme_test+0x00000068acb3)
    #4 el::base::RegisteredLoggers::get(std::string const&, bool) <null> (callme_test+0x00000068a89b)
    #5 el::Loggers::getLogger(std::string const&, bool) <null> (callme_test+0x000000689c35)
    #6 callme::dispatcher::dispatch(msgpack::v1::object const&) <null> (callme_test+0x0000006ccfc4)
    #7 callme::dispatcher::dispatch(msgpack::v1::sbuffer const&) <null> (callme_test+0x0000006ccdfc)
    #8 void binding_test::raw_call<unsigned char const (&) [23]>(unsigned char const (&) [23]) <null> (callme_test+0x00000064f3f7)
    #9 binding_test_freefunc_void_zeroarg_Test::TestBody() <null> (callme_test+0x000000649af6)
    #10 void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) <null> (callme_test+0x000000633222)
    #11 void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) <null> (callme_test+0x00000060453e)
    #12 testing::Test::Run() <null> (callme_test+0x0000005d6961)
    #13 testing::TestInfo::Run() <null> (callme_test+0x0000005d7934)
    #14 testing::TestCase::Run() <null> (callme_test+0x0000005d8290)
    #15 testing::internal::UnitTestImpl::RunAllTests() <null> (callme_test+0x0000005e2301)
    #16 bool testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) <null> (callme_test+0x0000006394d2)
    #17 bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) <null> (callme_test+0x000000607f54)
    #18 testing::UnitTest::Run() <null> (callme_test+0x0000005e1e1f)
    #19 RUN_ALL_TESTS() <null> (callme_test+0x00000064998d)
    #20 main <null> (callme_test+0x00000064994a)

My project and the commit in question is here. The unit test (callme_test) target will produce this error.

@johannesstricker
Copy link

Hi, I encountered the same problem with VS15. Has anyone resolved this, yet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants