[
https://issues.apache.org/jira/browse/LOGCXX-532?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17467551#comment-17467551
]
Stephen Webb commented on LOGCXX-532:
-------------------------------------
Using std::call_once to guard the exit(0) call, running multithreadtest
repeatedly still eventually causes a SegFault. The core dump shows
```
(gdb) info threads
Id Target Id Frame
* 1 Thread 0x7f26d9910700 (LWP 65907) 0x0000000000000007 in ?? ()
2 Thread 0x7f26cbfff700 (LWP 65910) 0x00007f26dc02e308 in
std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count(std::__weak_count<(__gnu_cxx::_Lock_policy)2>
const&, std::nothrow_t) () from
/home/stephen/build/asf-log4cxx/src/main/cpp/liblog4cxx.so.12
3 Thread 0x7f26da111700 (LWP 65906) 0x000055aaed11f6d0 in
std::uniform_int_distribution<int>::param_type::a() const ()
4 Thread 0x7f26d890e700 (LWP 65909) 0x000055aaed11ee22 in int
std::uniform_int_distribution<int>::operator()<std::mersenne_twister_engine<unsigned
long, 32ul, 624ul, 397ul, 31ul, 2567483615ul, 11ul, 4294967295ul, 7ul,
2636928640ul, 15ul, 4022730752ul, 18ul, 1812433253ul>
>(std::mersenne_twister_engine<unsigned long, 32ul, 624ul, 397ul, 31ul,
2567483615ul, 11ul, 4294967295ul, 7ul, 2636928640ul, 15ul, 4022730752ul, 18ul,
1812433253ul>&, std::uniform_int_distribution<int>::param_type const&) ()
5 Thread 0x7f26da912700 (LWP 65905) 0x00007f26dc06a09e in
std::shared_ptr<log4cxx::spi::LoggerRepository>::shared_ptr(std::weak_ptr<log4cxx::spi::LoggerRepository>
const&, std::nothrow_t) () from
/home/stephen/build/asf-log4cxx/src/main/cpp/liblog4cxx.so.12
6 Thread 0x7f26db6f3c80 (LWP 65904) __pthread_clockjoin_ex
(threadid=139804852430592, thread_return=0x0, clockid=<optimised out>,
abstime=<optimised out>, block=<optimised out>) at pthread_join_common.c:145
7 Thread 0x7f26d910f700 (LWP 65908) _fini () at ../sysdeps/x86_64/crti.S:83
(gdb) thread apply all backtrace
Thread 7 (Thread 0x7f26d910f700 (LWP 65908)):
#0 _fini () at ../sysdeps/x86_64/crti.S:83
#1 0x00007f26dc1adf7d in ?? () from /lib64/ld-linux-x86-64.so.2
#2 0x00007f26db937a27 in __run_exit_handlers (status=0, listp=0x7f26dbad9718
<__exit_funcs>, run_list_atexit=run_list_atexit@entry=true,
run_dtors=run_dtors@entry=true) at exit.c:108
#3 0x00007f26db937be0 in __GI_exit (status=<optimised out>) at exit.c:139
#4 0x000055aaed11f7b1 in void std::__invoke_impl<void, void (&)(int) noexcept,
int>(std::__invoke_other, void (&)(int) noexcept, int&&) ()
#5 0x000055aaed11ef7e in std::__invoke_result<void (&)(int) noexcept,
int>::type std::__invoke<void (&)(int) noexcept, int>(void (&)(int) noexcept,
int&&) ()
#6 0x000055aaed11e1f4 in std::call_once<void (&)(int) noexcept,
int>(std::once_flag&, void (&)(int) noexcept,
int&&)::\{lambda()#1}::operator()() const ()
#7 0x000055aaed11e21f in std::call_once<void (&)(int) noexcept,
int>(std::once_flag&, void (&)(int) noexcept,
int&&)::\{lambda()#2}::operator()() const ()
#8 0x000055aaed11e234 in std::call_once<void (&)(int) noexcept,
int>(std::once_flag&, void (&)(int) noexcept, int&&)::\{lambda()#2}::_FUN() ()
#9 0x00007f26dbcef47f in __pthread_once_slow (once_control=0x55aaed12f06c
<multithread_logger(int)::exiting>, init_routine=0x7f26dbbd0c20 <__once_proxy>)
at pthread_once.c:116
#10 0x000055aaed11d188 in __gthread_once(int*, void (*)()) ()
#11 0x000055aaed11e2c6 in void std::call_once<void (&)(int) noexcept,
int>(std::once_flag&, void (&)(int) noexcept, int&&) ()
#12 0x000055aaed11cfae in multithread_logger(int) ()
#13 0x000055aaed121bca in void std::__invoke_impl<void, void (*)(int),
int>(std::__invoke_other, void (*&&)(int), int&&) ()
#14 0x000055aaed121b2c in std::__invoke_result<void (*)(int), int>::type
std::__invoke<void (*)(int), int>(void (*&&)(int), int&&) ()
#15 0x000055aaed121a8b in void std::thread::_Invoker<std::tuple<void (*)(int),
int> >::_M_invoke<0ul, 1ul>(std::_Index_tuple<0ul, 1ul>) ()
#16 0x000055aaed121a42 in std::thread::_Invoker<std::tuple<void (*)(int), int>
>::operator()() ()
#17 0x000055aaed121a22 in
std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (*)(int), int> >
>::_M_run() ()
#18 0x00007f26dbbd1de4 in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
#19 0x00007f26dbce6609 in start_thread (arg=<optimised out>) at
pthread_create.c:477
#20 0x00007f26dba10293 in clone () at
../sysdeps/unix/sysv/linux/x86_64/clone.S:95
Thread 6 (Thread 0x7f26db6f3c80 (LWP 65904)):
#0 __pthread_clockjoin_ex (threadid=139804852430592, thread_return=0x0,
clockid=<optimised out>, abstime=<optimised out>, block=<optimised out>) at
pthread_join_common.c:145
#1 0x00007f26dbbd2047 in std::thread::join() () from
/lib/x86_64-linux-gnu/libstdc++.so.6
#2 0x000055aaed11deb0 in MultithreadTest::testMultithreadedLoggers() ()
#3 0x000055aaed11e493 in void LogUnit::runTest<MultithreadTest>(abts_case*,
void (MultithreadTest::*)()) ()
#4 0x000055aaed11da9e in
MultithreadTest::RegisterSuite::testMultithreadedLoggersRegistration::run(abts_case*,
void*) ()
#5 0x000055aaed1220ea in abts_run_test(abts_suite*, void (*)(abts_case*,
void*), void*) ()
#6 0x000055aaed12375f in LogUnit::TestSuite::run(abts_suite*) const ()
#7 0x000055aaed122d8c in abts_run_suites(abts_suite*) ()
#8 0x000055aaed122b66 in main ()
Thread 5 (Thread 0x7f26da912700 (LWP 65905)):
#0 0x00007f26dc06a09e in
std::shared_ptr<log4cxx::spi::LoggerRepository>::shared_ptr(std::weak_ptr<log4cxx::spi::LoggerRepository>
const&, std::nothrow_t) () from
/home/stephen/build/asf-log4cxx/src/main/cpp/liblog4cxx.so.12
#1 0x00007f26dc069bd3 in std::weak_ptr<log4cxx::spi::LoggerRepository>::lock()
const () from /home/stephen/build/asf-log4cxx/src/main/cpp/liblog4cxx.so.12
#2 0x00007f26dc066aeb in log4cxx::Logger::isInfoEnabled() const () from
/home/stephen/build/asf-log4cxx/src/main/cpp/liblog4cxx.so.12
#3 0x000055aaed11ce99 in multithread_logger(int) ()
#4 0x000055aaed121bca in void std::__invoke_impl<void, void (*)(int),
int>(std::__invoke_other, void (*&&)(int), int&&) ()
#5 0x000055aaed121b2c in std::__invoke_result<void (*)(int), int>::type
std::__invoke<void (*)(int), int>(void (*&&)(int), int&&) ()
#6 0x000055aaed121a8b in void std::thread::_Invoker<std::tuple<void (*)(int),
int> >::_M_invoke<0ul, 1ul>(std::_Index_tuple<0ul, 1ul>) ()
#7 0x000055aaed121a42 in std::thread::_Invoker<std::tuple<void (*)(int), int>
>::operator()() ()
#8 0x000055aaed121a22 in
std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (*)(int), int> >
>::_M_run() ()
#9 0x00007f26dbbd1de4 in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
#10 0x00007f26dbce6609 in start_thread (arg=<optimised out>) at
pthread_create.c:477
#11 0x00007f26dba10293 in clone () at
../sysdeps/unix/sysv/linux/x86_64/clone.S:95
Thread 4 (Thread 0x7f26d890e700 (LWP 65909)):
#0 0x000055aaed11ee22 in int
std::uniform_int_distribution<int>::operator()<std::mersenne_twister_engine<unsigned
long, 32ul, 624ul, 397ul, 31ul, 2567483615ul, 11ul, 4294967295ul, 7ul,
2636928640ul, 15ul, 4022730752ul, 18ul, 1812433253ul>
>(std::mersenne_twister_engine<unsigned long, 32ul, 624ul, 397ul, 31ul,
2567483615ul, 11ul, 4294967295ul, 7ul, 2636928640ul, 15ul, 4022730752ul, 18ul,
1812433253ul>&, std::uniform_int_distribution<int>::param_type const&) ()
#1 0x000055aaed11e1b3 in int
std::uniform_int_distribution<int>::operator()<std::mersenne_twister_engine<unsigned
long, 32ul, 624ul, 397ul, 31ul, 2567483615ul, 11ul, 4294967295ul, 7ul,
2636928640ul, 15ul, 4022730752ul, 18ul, 1812433253ul>
>(std::mersenne_twister_engine<unsigned long, 32ul, 624ul, 397ul, 31ul,
2567483615ul, 11ul, 4294967295ul, 7ul, 2636928640ul, 15ul, 4022730752ul, 18ul,
1812433253ul>&) ()
#2 0x000055aaed11cf77 in multithread_logger(int) ()
#3 0x000055aaed121bca in void std::__invoke_impl<void, void (*)(int),
int>(std::__invoke_other, void (*&&)(int), int&&) ()
#4 0x000055aaed121b2c in std::__invoke_result<void (*)(int), int>::type
std::__invoke<void (*)(int), int>(void (*&&)(int), int&&) ()
#5 0x000055aaed121a8b in void std::thread::_Invoker<std::tuple<void (*)(int),
int> >::_M_invoke<0ul, 1ul>(std::_Index_tuple<0ul, 1ul>) ()
--Type <RET> for more, q to quit, c to continue without paging--
#6 0x000055aaed121a42 in std::thread::_Invoker<std::tuple<void (*)(int), int>
>::operator()() ()
#7 0x000055aaed121a22 in
std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (*)(int), int> >
>::_M_run() ()
#8 0x00007f26dbbd1de4 in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
#9 0x00007f26dbce6609 in start_thread (arg=<optimised out>) at
pthread_create.c:477
#10 0x00007f26dba10293 in clone () at
../sysdeps/unix/sysv/linux/x86_64/clone.S:95
Thread 3 (Thread 0x7f26da111700 (LWP 65906)):
#0 0x000055aaed11f6d0 in std::uniform_int_distribution<int>::param_type::a()
const ()
#1 0x000055aaed11eef9 in int
std::uniform_int_distribution<int>::operator()<std::mersenne_twister_engine<unsigned
long, 32ul, 624ul, 397ul, 31ul, 2567483615ul, 11ul, 4294967295ul, 7ul,
2636928640ul, 15ul, 4022730752ul, 18ul, 1812433253ul>
>(std::mersenne_twister_engine<unsigned long, 32ul, 624ul, 397ul, 31ul,
2567483615ul, 11ul, 4294967295ul, 7ul, 2636928640ul, 15ul, 4022730752ul, 18ul,
1812433253ul>&, std::uniform_int_distribution<int>::param_type const&) ()
#2 0x000055aaed11e1b3 in int
std::uniform_int_distribution<int>::operator()<std::mersenne_twister_engine<unsigned
long, 32ul, 624ul, 397ul, 31ul, 2567483615ul, 11ul, 4294967295ul, 7ul,
2636928640ul, 15ul, 4022730752ul, 18ul, 1812433253ul>
>(std::mersenne_twister_engine<unsigned long, 32ul, 624ul, 397ul, 31ul,
2567483615ul, 11ul, 4294967295ul, 7ul, 2636928640ul, 15ul, 4022730752ul, 18ul,
1812433253ul>&) ()
#3 0x000055aaed11cf77 in multithread_logger(int) ()
#4 0x000055aaed121bca in void std::__invoke_impl<void, void (*)(int),
int>(std::__invoke_other, void (*&&)(int), int&&) ()
#5 0x000055aaed121b2c in std::__invoke_result<void (*)(int), int>::type
std::__invoke<void (*)(int), int>(void (*&&)(int), int&&) ()
#6 0x000055aaed121a8b in void std::thread::_Invoker<std::tuple<void (*)(int),
int> >::_M_invoke<0ul, 1ul>(std::_Index_tuple<0ul, 1ul>) ()
#7 0x000055aaed121a42 in std::thread::_Invoker<std::tuple<void (*)(int), int>
>::operator()() ()
#8 0x000055aaed121a22 in
std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (*)(int), int> >
>::_M_run() ()
#9 0x00007f26dbbd1de4 in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
#10 0x00007f26dbce6609 in start_thread (arg=<optimised out>) at
pthread_create.c:477
#11 0x00007f26dba10293 in clone () at
../sysdeps/unix/sysv/linux/x86_64/clone.S:95
Thread 2 (Thread 0x7f26cbfff700 (LWP 65910)):
#0 0x00007f26dc02e308 in
std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count(std::__weak_count<(__gnu_cxx::_Lock_policy)2>
const&, std::nothrow_t) () from
/home/stephen/build/asf-log4cxx/src/main/cpp/liblog4cxx.so.12
#1 0x00007f26dc06a469 in std::__shared_ptr<log4cxx::spi::LoggerRepository,
(__gnu_cxx::_Lock_policy)2>::__shared_ptr(std::__weak_ptr<log4cxx::spi::LoggerRepository,
(__gnu_cxx::_Lock_policy)2> const&, std::nothrow_t) () from
/home/stephen/build/asf-log4cxx/src/main/cpp/liblog4cxx.so.12
#2 0x00007f26dc06a0c5 in
std::shared_ptr<log4cxx::spi::LoggerRepository>::shared_ptr(std::weak_ptr<log4cxx::spi::LoggerRepository>
const&, std::nothrow_t) () from
/home/stephen/build/asf-log4cxx/src/main/cpp/liblog4cxx.so.12
#3 0x00007f26dc069bd3 in std::weak_ptr<log4cxx::spi::LoggerRepository>::lock()
const () from /home/stephen/build/asf-log4cxx/src/main/cpp/liblog4cxx.so.12
#4 0x00007f26dc066aeb in log4cxx::Logger::isInfoEnabled() const () from
/home/stephen/build/asf-log4cxx/src/main/cpp/liblog4cxx.so.12
#5 0x000055aaed11ce99 in multithread_logger(int) ()
#6 0x000055aaed121bca in void std::__invoke_impl<void, void (*)(int),
int>(std::__invoke_other, void (*&&)(int), int&&) ()
#7 0x000055aaed121b2c in std::__invoke_result<void (*)(int), int>::type
std::__invoke<void (*)(int), int>(void (*&&)(int), int&&) ()
#8 0x000055aaed121a8b in void std::thread::_Invoker<std::tuple<void (*)(int),
int> >::_M_invoke<0ul, 1ul>(std::_Index_tuple<0ul, 1ul>) ()
#9 0x000055aaed121a42 in std::thread::_Invoker<std::tuple<void (*)(int), int>
>::operator()() ()
#10 0x000055aaed121a22 in
std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (*)(int), int> >
>::_M_run() ()
#11 0x00007f26dbbd1de4 in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
#12 0x00007f26dbce6609 in start_thread (arg=<optimised out>) at
pthread_create.c:477
#13 0x00007f26dba10293 in clone () at
../sysdeps/unix/sysv/linux/x86_64/clone.S:95
Thread 1 (Thread 0x7f26d9910700 (LWP 65907)):
#0 0x0000000000000007 in ?? ()
#1 0x00007f26dbff0496 in
log4cxx::AppenderSkeleton::isAsSevereAsThreshold(std::shared_ptr<log4cxx::Level>
const&) const () from
/home/stephen/build/asf-log4cxx/src/main/cpp/liblog4cxx.so.12
#2 0x00007f26dbff06a1 in
log4cxx::AppenderSkeleton::doAppendImpl(std::shared_ptr<log4cxx::spi::LoggingEvent>
const&, log4cxx::helpers::Pool&) () from
/home/stephen/build/asf-log4cxx/src/main/cpp/liblog4cxx.so.12
#3 0x00007f26dbff0515 in
log4cxx::AppenderSkeleton::doAppend(std::shared_ptr<log4cxx::spi::LoggingEvent>
const&, log4cxx::helpers::Pool&) () from
/home/stephen/build/asf-log4cxx/src/main/cpp/liblog4cxx.so.12
#4 0x00007f26dbfebe58 in
log4cxx::helpers::AppenderAttachableImpl::appendLoopOnAppenders(std::shared_ptr<log4cxx::spi::LoggingEvent>
const&, log4cxx::helpers::Pool&) () from
/home/stephen/build/asf-log4cxx/src/main/cpp/liblog4cxx.so.12
#5 0x00007f26dc065a68 in
log4cxx::Logger::callAppenders(std::shared_ptr<log4cxx::spi::LoggingEvent>
const&, log4cxx::helpers::Pool&) const () from
/home/stephen/build/asf-log4cxx/src/main/cpp/liblog4cxx.so.12
#6 0x00007f26dc065d13 in
log4cxx::Logger::forcedLog(std::shared_ptr<log4cxx::Level> const&,
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >
const&, log4cxx::spi::LocationInfo const&) const () from
/home/stephen/build/asf-log4cxx/src/main/cpp/liblog4cxx.so.12
#7 0x000055aaed11cf40 in multithread_logger(int) ()
#8 0x000055aaed121bca in void std::__invoke_impl<void, void (*)(int),
int>(std::__invoke_other, void (*&&)(int), int&&) ()
#9 0x000055aaed121b2c in std::__invoke_result<void (*)(int), int>::type
std::__invoke<void (*)(int), int>(void (*&&)(int), int&&) ()
#10 0x000055aaed121a8b in void std::thread::_Invoker<std::tuple<void (*)(int),
int> >::_M_invoke<0ul, 1ul>(std::_Index_tuple<0ul, 1ul>) ()
#11 0x000055aaed121a42 in std::thread::_Invoker<std::tuple<void (*)(int), int>
>::operator()() ()
--Type <RET> for more, q to quit, c to continue without paging--
#12 0x000055aaed121a22 in
std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (*)(int), int> >
>::_M_run() ()
#13 0x00007f26dbbd1de4 in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
#14 0x00007f26dbce6609 in start_thread (arg=<optimised out>) at
pthread_create.c:477
#15 0x00007f26dba10293 in clone () at
../sysdeps/unix/sysv/linux/x86_64/clone.S:95
```
> Static objects and deleting
> ---------------------------
>
> Key: LOGCXX-532
> URL: https://issues.apache.org/jira/browse/LOGCXX-532
> Project: Log4cxx
> Issue Type: Improvement
> Reporter: Robert Middleton
> Assignee: Robert Middleton
> Priority: Minor
>
> As seen in LOGCXX-430 and LOGCXX-322, making sure that when an application
> terminates earlier than expected we don't crash is rather hard to do.
> I came across this solution when researching this problem:
> https://stackoverflow.com/a/470545/624483
> My thought is that we create something like a log4cxx::Globals class, which
> contains a smart pointer to everything that must be kept alive before the
> library can safely be unloaded. In each thread, you would do something like:
> {{GlobalsPtr globals = log4cxx::globals;}}
> thus ensuring that the destructor can't run before all of the threads are
> stopped. This would be up to the user of the library.
--
This message was sent by Atlassian Jira
(v8.20.1#820001)