Boost C++ Libraries: Ticket #10381: Boost log mutex lock failure https://svn.boost.org/trac10/ticket/10381 <p> I'm using add_console_log(), passing it std::clog. When I build in release with optimizations, everything works fine. When building in debug without optimizations though, when my program exits there's a core dump as a result of the assertion on destruction of the mutex lock failing (pthread_mutex_destroy() is returning 16, which iic is EBUSY). I started digging through add_console_log(), and if I switch to an asynchronous sink there's no issues (I suppose it doesn't need the mutex lock anymore and that's why) My compiler's 4.8.3 on FC 20. I've tried with 1.55 and 1.56. </p> <p> The code that results in the core dump: </p> <pre class="wiki">typedef boost::log::sources::severity_logger&lt;severity_level&gt; lgr_type; BOOST_LOG_GLOBAL_LOGGER(logger, lgr_type); ... BOOST_LOG_GLOBAL_LOGGER_INIT(logger, src::severity_logger_mt) { // setup the console sink typedef boost::log::sinks::synchronous_sink&lt;boost::log::sinks::text_ostream_backend&gt; text_sink; boost::shared_ptr&lt;text_sink&gt; consoleSink = boost::log::add_console_log(std::clog; lgr_type lgr; return lgr; } ... BOOST_LOG_SEV(logger::get(), SEV_LVL_TRACE) &lt;&lt; "a message"; </pre><pre class="wiki">Thread [1] 29960 [core: 6] (Suspended : Signal : SIGABRT:Aborted) raise() at 0x3215035c39 abort() at 0x3215037348 __assert_fail_base() at 0x321502eb96 __assert_fail() at 0x321502ec42 boost::mutex::~mutex() at mutex.hpp:108 0x7ffff7b5fb8b boost::log::v2_mt_posix::sinks::synchronous_sink&lt;boost::log::v2_mt_posix::sinks::basic_text_ostream_backend&lt;char&gt; &gt;::~synchronous_sink() at sync_frontend.hpp:61 0x7ffff7b6c7af boost::detail::sp_ms_deleter&lt;boost::log::v2_mt_posix::sinks::synchronous_sink&lt;boost::log::v2_mt_posix::sinks::basic_text_ostream_backend&lt;char&gt; &gt; &gt;::destroy() at make_shared_object.hpp:57 0x7ffff7b6c890 boost::detail::sp_ms_deleter&lt;boost::log::v2_mt_posix::sinks::synchronous_sink&lt;boost::log::v2_mt_posix::sinks::basic_text_ostream_backend&lt;char&gt; &gt; &gt;::operator() at make_shared_object.hpp:87 0x7ffff7b79dca boost::detail::sp_counted_impl_pd&lt;boost::log::v2_mt_posix::sinks::synchronous_sink&lt;boost::log::v2_mt_posix::sinks::basic_text_ostream_backend&lt;char&gt; &gt;*, boost::detail::sp_ms_deleter&lt;boost::log::v2_mt_posix::sinks::synchronous_sink&lt;boost::log::v2_mt_posix::sinks::basic_text_ostream_backend&lt;char&gt; &gt; &gt; &gt;::dispose() at sp_counted_impl.hpp:153 0x7ffff7b78f6d boost::log::v2_mt_posix::core::~core() at 0x7ffff7459100 &lt;...more frames...&gt; </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/10381 Trac 1.4.3 Antony Polukhin Fri, 22 Aug 2014 13:52:31 GMT component changed; owner set https://svn.boost.org/trac10/ticket/10381#comment:1 https://svn.boost.org/trac10/ticket/10381#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">Andrey Semashev</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">log</span> </li> </ul> Ticket Andrey Semashev Fri, 22 Aug 2014 14:33:02 GMT <link>https://svn.boost.org/trac10/ticket/10381#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10381#comment:2</guid> <description> <p> I cannot reproduce it with the code from the description. Could you provide the compilable code sample that demonstrates the problem? </p> <p> Also, if your application is multithreaded, make sure you join all threads before the application terminates. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>mirous</dc:creator> <pubDate>Thu, 25 Sep 2014 10:38:44 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10381#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10381#comment:3</guid> <description> <p> I'm having the same problem. My environment is debian testing, x86_64, gcc 4.9.1, libboost 1.55. </p> <p> I stripped down the code to this minimum, main.cpp: </p> <pre class="wiki">#include &lt;boost/log/trivial.hpp&gt; #include &lt;boost/log/utility/setup/console.hpp&gt; #include &lt;boost/log/utility/setup/common_attributes.hpp&gt; namespace logging = boost::log; int main(int argc, char *argv[]) { logging::add_console_log(); logging::add_common_attributes(); BOOST_LOG_TRIVIAL(info) &lt;&lt; "Application starting.."; } </pre><p> Compiled with </p> <pre class="wiki">gcc -Wall -O2 -g -std=c++11 -DBOOST_LOG_DYN_LINK -o main main.cpp -lstdc++ -lboost_log -lpthread -lboost_thread -lboost_system </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>Andrey Semashev</dc:creator> <pubDate>Sat, 27 Sep 2014 15:18:06 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10381#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10381#comment:4</guid> <description> <p> I don't have gcc 4.9 locally but it doesn't crash for me with gcc 4.8.2. Tried with Boost 1.55 and recent develop branch. Note that you missed -lboost_filesystem in the command line. </p> <p> Does it crash every time or is it not stable? Could you attach a backtrace of the crash (e.g. run the test from gdb and then execute 'thread apply all bt')? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>mirous</dc:creator> <pubDate>Mon, 29 Sep 2014 14:27:53 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10381#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10381#comment:5</guid> <description> <p> It crashes every time. I tried it with gcc 4.8 &amp; 4.7 on the same system and it crashes as well. </p> <p> The backtrace: </p> <pre class="wiki">#0 0x00007ffff6a16077 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56 #1 0x00007ffff6a17458 in __GI_abort () at abort.c:89 #2 0x00007ffff6a0f196 in __assert_fail_base (fmt=0x7ffff6b458c8 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=assertion@entry=0x4120d0 "!posix::pthread_mutex_destroy(&amp;m)", file=file@entry=0x4120a0 "/usr/include/boost/thread/pthread/mutex.hpp", line=line@entry=108, function=function@entry=0x412960 &lt;boost::mutex::~mutex()::__PRETTY_FUNCTION__&gt; "boost::mutex::~mutex()") at assert.c:92 #3 0x00007ffff6a0f242 in __GI___assert_fail (assertion=0x4120d0 "!posix::pthread_mutex_destroy(&amp;m)", file=0x4120a0 "/usr/include/boost/thread/pthread/mutex.hpp", line=108, function=0x412960 &lt;boost::mutex::~mutex()::__PRETTY_FUNCTION__&gt; "boost::mutex::~mutex()") at assert.c:101 #4 0x000000000040cda4 in ~mutex (this=0x61a850, __in_chrg=&lt;optimized out&gt;) at /usr/include/boost/thread/pthread/mutex.hpp:108 #5 boost::log::v2_mt_posix::sinks::synchronous_sink&lt;boost::log::v2_mt_posix::sinks::basic_text_ostream_backend&lt;char&gt; &gt;::~synchronous_sink (this=0x61a7c0, __in_chrg=&lt;optimized out&gt;) at /usr/include/boost/log/sinks/sync_frontend.hpp:61 #6 0x000000000040b58e in destroy (this=0x61a7b8) at /usr/include/boost/smart_ptr/make_shared_object.hpp:57 #7 operator() (this=0x61a7b8) at /usr/include/boost/smart_ptr/make_shared_object.hpp:87 #8 boost::detail::sp_counted_impl_pd&lt;boost::log::v2_mt_posix::sinks::synchronous_sink&lt;boost::log::v2_mt_posix::sinks::basic_text_ostream_backend&lt;char&gt; &gt;*, boost::detail::sp_ms_deleter&lt;boost::log::v2_mt_posix::sinks::synchronous_sink&lt;boost::log::v2_mt_posix::sinks::basic_text_ostream_backend&lt;char&gt; &gt; &gt; &gt;::dispose (this=0x61a7a0) at /usr/include/boost/smart_ptr/detail/sp_counted_impl.hpp:153 #9 0x00007ffff7853ab8 in boost::log::v2_mt_posix::core::~core() () from /usr/lib/x86_64-linux-gnu/libboost_log.so.1.55.0 #10 0x00007ffff7856262 in boost::detail::sp_counted_impl_p&lt;boost::log::v2_mt_posix::core&gt;::dispose() () from /usr/lib/x86_64-linux-gnu/libboost_log.so.1.55.0 #11 0x00007ffff7855eb9 in boost::shared_ptr&lt;boost::log::v2_mt_posix::core&gt;::~shared_ptr() () from /usr/lib/x86_64-linux-gnu/libboost_log.so.1.55.0 #12 0x00007ffff6a18b39 in __run_exit_handlers (status=0, listp=0x7ffff6d835a8 &lt;__exit_funcs&gt;, run_list_atexit=run_list_atexit@entry=true) at exit.c:82 #13 0x00007ffff6a18b85 in __GI_exit (status=&lt;optimized out&gt;) at exit.c:104 #14 0x00007ffff6a02b4c in __libc_start_main (main=0x40a630 &lt;main(int, char**)&gt;, argc=1, argv=0x7fffffffe398, init=&lt;optimized out&gt;, fini=&lt;optimized out&gt;, rtld_fini=&lt;optimized out&gt;, stack_end=0x7fffffffe388) at libc-start.c:321 #15 0x000000000040ab34 in _start () </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>Andrey Semashev</dc:creator> <pubDate>Sat, 25 Apr 2015 20:40:01 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/10381#comment:6 https://svn.boost.org/trac10/ticket/10381#comment:6 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">worksforme</span> </li> </ul> <p> I cannot reproduce this. If it still happens, please attach a self-contained reproducing code sample. </p> Ticket