abumq / easyloggingpp

C++ logging library. It is powerful, supports asynchronous low latency, extendable, light-weight, fast performing, thread and type safe and consists of many built-in features. It provides ability to write logs in your own customized format. It also provide support for logging your classes, third-party libraries, STL and third-party containers etc.
MIT License
3.76k stars 921 forks source link

multiple thread will crash Segmentation fault #625

Closed polandeme closed 6 years ago

polandeme commented 6 years ago

I have used


#include <thread>
#include <pthread.h>
...
#define ELPP_THREAD_SAFE
#define ELPP_FORCE_USE_STD_THREAD
#include "easylogging++.h"

complier options is:

-DELPP_NO_DEFAULT_LOG_FILE -DELPP_THREAD_SAFE -g -pipe -fPIC -pthread --std=c++0x -Wmissing-field-initializers -fpermissive 

gcc version 4.8.2 Linux 64

but when I run at 30 thread will crash, the core is:

#0  0x00007f713143c494 in pthread_mutex_lock () from /opt/compiler/gcc-4.8.2/lib/libpthread.so.0
(gdb) bt
#0  0x00007f713143c494 in pthread_mutex_lock () from /opt/compiler/gcc-4.8.2/lib/libpthread.so.0
#1  0x00007f71304fc7f4 in __gthread_mutex_lock (__mutex=0x48000000002040cf)
    at /home/opt/gcc-4.8.2.bpkg-r4/gcc-4.8.2.bpkg-r4/include/c++/4.8.2/x86_64-baidu-linux-gnu/bits/gthr-default.h:748
#2  0x00007f71304fc844 in __gthread_recursive_mutex_lock (__mutex=0x48000000002040cf)
    at /home/opt/gcc-4.8.2.bpkg-r4/gcc-4.8.2.bpkg-r4/include/c++/4.8.2/x86_64-baidu-linux-gnu/bits/gthr-default.h:810
#3  0x00007f713050e6fc in std::recursive_mutex::lock (this=0x48000000002040cf)
    at /home/opt/gcc-4.8.2.bpkg-r4/gcc-4.8.2.bpkg-r4/include/c++/4.8.2/mutex:175
#4  0x00007f7130511104 in std::lock_guard<std::recursive_mutex>::lock_guard (this=0x7f712ed81a30, 
    __m=...) at /home/opt/gcc-4.8.2.bpkg-r4/gcc-4.8.2.bpkg-r4/include/c++/4.8.2/mutex:414
#5  0x00007f71305122c2 in el::base::TypedConfigurations::getConfigByVal<bool> (this=0x48000000002040c7, 
    level=796407840, confMap=0x480000000020418f, confName=0x7f71305333d3 "toStandardOutput")
    at baidu/aip-ics/unimrcp-plugins/libs/thirdparty/easylogging/easylogging++.h:2013
#6  0x00007f7130504f4e in el::base::TypedConfigurations::toStandardOutput (this=0x48000000002040c7, 
    level=796407840) at baidu/aip-ics/unimrcp-plugins/libs/thirdparty/easylogging/easylogging++.cc:1564
#7  0x00007f7130509694 in el::base::DefaultLogDispatchCallback::dispatch(std::string&&) (this=0x62bac0, 
    logLine=<unknown type in /home/work/huangguorui/mrcp/output/output/unimrcp/plugin/libpaasrecog.so, CU 0x0, DIE 0x49a6a>) at baidu/aip-ics/unimrcp-plugins/libs/thirdparty/easylogging/easylogging++.cc:2155
#8  0x00007f7130509414 in el::base::DefaultLogDispatchCallback::handle (this=0x62bac0, 
    data=0x7f712ed81b50)
    at baidu/aip-ics/unimrcp-plugins/libs/thirdparty/easylogging/easylogging++.cc:2128
#9  0x00007f713050a836 in el::base::LogDispatcher::dispatch (this=0x7f712ed81d40)
    at baidu/aip-ics/unimrcp-plugins/libs/thirdparty/easylogging/easylogging++.cc:2408
#10 0x00007f713050b4f2 in el::base::Writer::triggerDispatch (this=0x7f712ed82020)
    at baidu/aip-ics/unimrcp-plugins/libs/thirdparty/easylogging/easylogging++.cc:2539
#11 0x00007f713050b2c6 in el::base::Writer::processDispatch (this=0x7f712ed82020)
    at baidu/aip-ics/unimrcp-plugins/libs/thirdparty/easylogging/easylogging++.cc:2522
#12 0x00007f71305100a4 in el::base::Writer::~Writer (this=0x7f712ed82020, __in_chrg=<optimized out>)
    at baidu/aip-ics/unimrcp-plugins/libs/thirdparty/easylogging/easylogging++.h:3258
#13 0x00007f71301eb4cb in baidu::itma::ItmaControllerImpl::new_session(std::string const&, Json::Value const&, baidu::itma::ItmaSession*&, std::string&) ()
   from /home/work/huangguorui/mrcp/output/output/unimrcp/plugin/libbd_itma.so.0.1.3
#14 0x00007f71301eb807 in baidu::itma::ItmaControllerImpl::new_session(Json::Value const&, baidu::itma::ItmaSession*&, std::string&) ()
   from /home/work/huangguorui/mrcp/output/output/unimrcp/plugin/libbd_itma.so.0.1.3
#15 0x00007f713052acf7 in init_itma_sdk_session (recog_channel=0x7f70f4018718)
    at baidu/aip-ics/unimrcp-plugins/include/init_helper.h:115
#16 0x00007f713052e347 in paas_recog_channel_recognize (channel=0x7f70f40192c8, request=0x7f70f802b030, 
    response=0x7f70f8031b60) at baidu/aip-ics/unimrcp-plugins/src/paas_recog_engine.cpp:708
#17 0x00007f713052e879 in paas_recog_channel_request_dispatch (channel=0x7f70f40192c8, 
    request=0x7f70f802b030) at baidu/aip-ics/unimrcp-plugins/src/paas_recog_engine.cpp:761
#18 0x00007f713052dfc8 in paas_recog_msg_process (task=0x62e008, msg=0x7f712800fa80)
    at baidu/aip-ics/unimrcp-plugins/src/paas_recog_engine.cpp:639
#19 0x00007f7133152b51 in apt_task_msg_process (task=0x62e008, msg=0x7f712800fa80) at src/apt_task.c:344
#20 0x00007f7133152f27 in apt_consumer_task_run (task=<optimized out>) at src/apt_consumer_task.c:147
#21 0x00007f7133152180 in apt_task_run (thread_handle=0x62e958, data=0x62e008) at src/apt_task.c:591
#22 0x00007f713143a1c3 in start_thread () from /opt/compiler/gcc-4.8.2/lib/libpthread.so.0
#23 0x00007f7130e6912d in clone () from /opt/compiler/gcc-4.8.2/lib/libc.so.6

I don't no why is it? please help me.

THX

abumq commented 6 years ago

can you post a simple code to reproduce and full compiler command

Also you can remove DEFINES from header file as you already have in compiler options

#define ELPP_THREAD_SAFE
#define ELPP_FORCE_USE_STD_THREAD
polandeme commented 6 years ago

@abumusamq I remove DEFINE ,but it is still not woke. just warn redefine.

Sorry, I change to spdlog. because it will deadline。

abumq commented 6 years ago

@polandeme i was after a minimal code to reproduce the issue. i cannot reproduce this as it works just fine. no problems feel free to switch.