Re: [Cppcms-users] Segmentaion fault occurs to booster::aio::io_service running in booster::thread
Brought to you by:
artyom-beilis
From: Marcel H. <ke...@co...> - 2016-05-09 06:38:22
|
I'm not entirely sure, but don't you need something like '-pthread' to use threads in a unix environment. Try that out. On 05/08/2016 04:04 PM, CN wrote: > File "t.cpp": > > #include <booster/aio/io_service.h> > #include <cppcms/service.h> > #include <boost/bind.hpp> > #include <booster/shared_ptr.h> > #include <booster/log.h> > #include <signal.h> > booster::shared_ptr<cppcms::service> this_cppcms_service; > static int caught_signal=-1; > > void signal_handler(int signal_number) > { > BOOSTER_DEBUG("begin handler"); > caught_signal=signal_number; > this_cppcms_service->shutdown(); > BOOSTER_DEBUG("end handler"); > } > > class my_class { > private: > booster::aio::io_service io_service; > public: > void start(){ > io_service.run(); > } > void stop(){ > io_service.stop(); > } > }; > > > int main(int argc,char ** argv) > { > while(true){ > try{ > this_cppcms_service.reset(new > cppcms::service(argc,argv)); > //Install signals catchers. > struct sigaction actions; > memset(&actions,0,sizeof(actions)); > actions.sa_handler=signal_handler; > int result; > if( > (result=sigaction(SIGTERM,&actions,NULL)) > != 0 > || > (result=sigaction(SIGHUP,&actions,NULL)) > != 0 > ){ > BOOSTER_ERROR("") << "sigaction() > failed"; > exit(EXIT_FAILURE); > } > my_class mc; > booster::thread > mc_thread(boost::bind(&my_class::start,&mc)); > > BOOSTER_DEBUG("==1=="); > this_cppcms_service->run(); > BOOSTER_DEBUG("==2=="); > mc.stop(); mc_thread.join(); > BOOSTER_DEBUG("==3=="); > if(caught_signal == SIGTERM) > return 0; > BOOSTER_DEBUG("==4=="); > //SIGHUP to reload configurations > } > catch(std::exception const &e){ > BOOSTER_ERROR("") << e.what(); > return 1; > } > } > return 0; > } > > ---------- > > File "t.js": > > { > "service" : { > "api" : "fastcgi", > "socket" : "/tmp/t.sock", > "disable_global_exit_handling":true > }, > "daemon":{ > "enable":true, > "lock":"/tmp/t.pid" > }, > "logging" : { > "level" : "debug", > "stderr" : false, > "syslog" : { > "enable":true, > "id" : "t" > } > } > } > > -------- > > Commands issued: > > cd /tmp > g++ -lbooster -lcppcms -lboost_system t.cpp > ./a.out -c t.js > kill -TERM `cat t.pid` > > -------- > > File "/var/log/syslog": > > May 8 21:36:13 host t: ==1==: (t.cpp:51) > May 8 21:36:36 host t: begin handler: (t.cpp:12) > May 8 21:36:36 host t: end handler: (t.cpp:15) > May 8 21:36:36 host t: ==2==: (t.cpp:53) > May 8 21:36:36 host kernel: a.out[5146]: segfault at b5b5dba8 ip > b715205e sp bfad0620 error 4 in libpthread-2.19.so[b714a000+18000] > > > With this simple code, I get segfault at "mc.stop(); mc_thread.join();" > after issuing command "kill -TERM <pid>". Would someone please enlighten > me why? > > Best regards, > CN > |