落单de雄狮 发表于 2013-1-9 16:50:32

求助:关于Reactor的标准写法,内贴coredump代码

ACE_THR_FUNC_RETURN thread_fun(void *arg)
{
      TimerEventHandler hd;
      SignalEventHandler sd(62);
      ACE_Reactor::instance()->run_reactor_event_loop();
      return 0;
}

int main(int argc,char *argv[])
{

      if (0)
      {
                TimerEventHandler hd;
                SignalEventHandler sd(62);
                ACE_Reactor::instance()->run_reactor_event_loop();
      }
      else
      {
                ACE_Thread_Manager::instance()->spawn_n(1, thread_fun,
                              reinterpret_cast<void *>(ACE_Reactor::instance()));

                ACE_Thread_Manager::instance()->wait();
      }

      return 0;
}
在启动线程来run_reactor_event_loop调试过程中,出现coredump.
根据coredump可知,是在reactor调用event_handler->handle_close方法时错误.
麻烦请问此类程序的标准写法应该如何?

以下附堆栈信息:
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7ae7635 in cancel_type (requires_reference_counting=<value optimized out>, dont_call=<value optimized out>, event_handler=<value optimized out>, this=<value optimized out>)
    at ../../ace/Timer_Queue_T.cpp:441
441          event_handler->handle_close (ACE_INVALID_HANDLE,
(gdb) bt
#00x00007ffff7ae7635 in cancel_type (requires_reference_counting=<value optimized out>, dont_call=<value optimized out>, event_handler=<value optimized out>, this=<value optimized out>)
    at ../../ace/Timer_Queue_T.cpp:441
#1deletion (requires_reference_counting=<value optimized out>, dont_call=<value optimized out>, event_handler=<value optimized out>, this=<value optimized out>)
    at ../../ace/Timer_Queue_T.cpp:466
#2ACE_Timer_Heap_T<ACE_Event_Handler*, ACE_Event_Handler_Handle_Timeout_Upcall<ACE_Recursive_Thread_Mutex>, ACE_Recursive_Thread_Mutex>::~ACE_Timer_Heap_T (
    requires_reference_counting=<value optimized out>, dont_call=<value optimized out>, event_handler=<value optimized out>, this=<value optimized out>) at ../../ace/Timer_Heap_T.cpp:222
#30x00007ffff7ae4e92 in ACE_Select_Reactor_T<ACE_Reactor_Token_T<ACE_Token> >::close (this=0x60a8c0) at ../../ace/Select_Reactor_T.cpp:576
#40x00007ffff7b56e90 in ACE_Reactor::~ACE_Reactor (this=0x60a8a0, __in_chrg=<value optimized out>) at ../../ace/Reactor.cpp:117
#50x00007ffff7b5758a in ACE_Reactor::close_singleton () at ../../ace/Reactor.cpp:183
#60x00007ffff7b57e6b in ACE_Framework_Component_T<ACE_Reactor>::~ACE_Framework_Component_T (this=0x7ffff691e070, __in_chrg=<value optimized out>) at ../../ace/Framework_Component_T.cpp:21
#70x00007ffff7b09d01 in ACE_Framework_Repository::close (this=0x60d550) at ../../ace/Framework_Component.cpp:78
#80x00007ffff7b09d6d in ACE_Framework_Repository::~ACE_Framework_Repository (this=0x7ffff691e070, __in_chrg=<value optimized out>) at ../../ace/Framework_Component.cpp:40
#90x00007ffff7b09e20 in ACE_Framework_Repository::close_singleton () at ../../ace/Framework_Component.cpp:123
#10 0x00007ffff7b37454 in ACE_Object_Manager::fini (this=0x6041b0) at ../../ace/Object_Manager.cpp:751
#11 0x00007ffff7b37568 in ACE_Object_Manager::~ACE_Object_Manager (this=0x7ffff691e070, __in_chrg=<value optimized out>) at ../../ace/Object_Manager.cpp:417
#12 0x00007ffff7b372a5 in ACE_Object_Manager_Manager::~ACE_Object_Manager_Manager (this=<value optimized out>, __in_chrg=<value optimized out>) at ../../ace/Object_Manager.cpp:882
#13 0x00007ffff6f7d3e5 in __cxa_finalize () from /lib64/libc.so.6
#14 0x00007ffff7ad4b86 in __do_global_dtors_aux () from /usr/local/lib/libACE-5.7.5.so
#15 0x0000000000000000 in ?? ()
(gdb) f 0
#00x00007ffff7ae7635 in cancel_type (requires_reference_counting=<value optimized out>, dont_call=<value optimized out>, event_handler=<value optimized out>, this=<value optimized out>)
    at ../../ace/Timer_Queue_T.cpp:441
441          event_handler->handle_close (ACE_INVALID_HANDLE,

落单de雄狮 发表于 2013-1-9 17:19:17

郁闷阿,找了好久
ACE_Thread_Manager::instance()->spawn_n(1, thread_fun,
                                 reinterpret_cast<void *>(ACE_Reactor::instance()));
改成:
ACE_Thread_Manager::instance()->spawn_n(1, thread_fun,NULL);
就OK了.但不知道为什么.

落单de雄狮 发表于 2013-1-9 17:37:34

自问自答了,调了好久.最后得出一个结论,每个线程一个reactor,否则要coredump.如果不是,求教

落单de雄狮 发表于 2013-1-11 21:41:19

经过测试后,发现是没有remove_handler导致,因为Reactor析构时调用了 event_handler->close_handle。
而本身没有new ACE_Event_Handler出来,并且没有在handle_close里面delete this.

落单de雄狮 发表于 2013-1-11 21:42:17

属于是ACE_Event_Handler生命周期使用有误,属于Reactor基本使用错误。
页: [1]
查看完整版本: 求助:关于Reactor的标准写法,内贴coredump代码