找回密码
 用户注册

QQ登录

只需一步,快速开始

查看: 14971|回复: 4

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

[复制链接]
发表于 2013-1-9 16:50:32 | 显示全部楼层 |阅读模式
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
#0  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
#1  deletion (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
#2  ACE_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
#3  0x00007ffff7ae4e92 in ACE_Select_Reactor_T<ACE_Reactor_Token_T<ACE_Token> >::close (this=0x60a8c0) at ../../ace/Select_Reactor_T.cpp:576
#4  0x00007ffff7b56e90 in ACE_Reactor::~ACE_Reactor (this=0x60a8a0, __in_chrg=<value optimized out>) at ../../ace/Reactor.cpp:117
#5  0x00007ffff7b5758a in ACE_Reactor::close_singleton () at ../../ace/Reactor.cpp:183
#6  0x00007ffff7b57e6b 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
#7  0x00007ffff7b09d01 in ACE_Framework_Repository::close (this=0x60d550) at ../../ace/Framework_Component.cpp:78
#8  0x00007ffff7b09d6d in ACE_Framework_Repository::~ACE_Framework_Repository (this=0x7ffff691e070, __in_chrg=<value optimized out>) at ../../ace/Framework_Component.cpp:40
#9  0x00007ffff7b09e20 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
#0  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,
 楼主| 发表于 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了.但不知道为什么.
 楼主| 发表于 2013-1-9 17:37:34 | 显示全部楼层
自问自答了,调了好久.最后得出一个结论,每个线程一个reactor,否则要coredump.如果不是,求教
 楼主| 发表于 2013-1-11 21:41:19 | 显示全部楼层
经过测试后,发现是没有remove_handler导致,因为Reactor析构时调用了 event_handler->close_handle。
而本身没有new ACE_Event_Handler出来,并且没有在handle_close里面delete this.
 楼主| 发表于 2013-1-11 21:42:17 | 显示全部楼层
属于是ACE_Event_Handler生命周期使用有误,属于Reactor基本使用错误。
您需要登录后才可以回帖 登录 | 用户注册

本版积分规则

Archiver|手机版|小黑屋|ACE Developer ( 京ICP备06055248号 )

GMT+8, 2024-12-22 16:18 , Processed in 0.017287 second(s), 6 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表