关闭

ACE_Thread_Manager和WinMain冲突问题

1089人阅读 评论(1) 收藏 举报
分类:
今天在一个Windows的程序中使用了ACE_Thread_Manager::instance ()->spawn来创建新的线程,结果发现程序崩溃。然后改用ACE_Thread::spawn后确发现没有问题,为什么会这样呢?

--------------------------------------------------
author: cs_cjl
website: http://blog.csdn.net/cs_cjl
--------------------------------------------------

第一时间想到的是使用StackWalker打印崩溃的堆栈信息:
Dec 03 18:43:27.807 2013@LM_EMERGENCY@ (8808) OnDbgHelpErr: SymGetLineFromAddr64, GetLastError: 487 (Address: 779B22D2)
Dec 03 18:43:27.807 2013@LM_EMERGENCY@ (8808) 779B22D2 (ntdll): (filename not available): RtlEnterCriticalSection
Dec 03 18:43:27.807 2013@LM_EMERGENCY@ (8808) OnDbgHelpErr: SymGetLineFromAddr64, GetLastError: 487 (Address: 0FFF6D9D)
Dec 03 18:43:27.807 2013@LM_EMERGENCY@ (8808) 0FFF6D9D (ACEd): (filename not available): ACE_OS::thread_mutex_lock
Dec 03 18:43:27.807 2013@LM_EMERGENCY@ (8808) OnDbgHelpErr: SymGetLineFromAddr64, GetLastError: 487 (Address: 100304D0)
Dec 03 18:43:27.807 2013@LM_EMERGENCY@ (8808) 100304D0 (ACEd): (filename not available): ACE_Thread_Mutex::acquire
Dec 03 18:43:27.807 2013@LM_EMERGENCY@ (8808) OnDbgHelpErr: SymGetLineFromAddr64, GetLastError: 487 (Address: 0FF7B8F3)
Dec 03 18:43:27.807 2013@LM_EMERGENCY@ (8808) 0FF7B8F3 (ACEd): (filename not available): ACE_Task<ACE_NULL_SYNCH>::dump
Dec 03 18:43:27.807 2013@LM_EMERGENCY@ (8808) OnDbgHelpErr: SymGetLineFromAddr64, GetLastError: 487 (Address: 0FF77131)
Dec 03 18:43:27.807 2013@LM_EMERGENCY@ (8808) 0FF77131 (ACEd): (filename not available): ACE_Task<ACE_NULL_SYNCH>::dump
Dec 03 18:43:27.807 2013@LM_EMERGENCY@ (8808) OnDbgHelpErr: SymGetLineFromAddr64, GetLastError: 487 (Address: 10029C5D)
Dec 03 18:43:27.807 2013@LM_EMERGENCY@ (8808) 10029C5D (ACEd): (filename not available): ACE_Thread_Exit::instance
Dec 03 18:43:27.808 2013@LM_EMERGENCY@ (8808) OnDbgHelpErr: SymGetLineFromAddr64, GetLastError: 487 (Address: 10029853)
Dec 03 18:43:27.808 2013@LM_EMERGENCY@ (8808) 10029853 (ACEd): (filename not available): ACE_Thread_Adapter::invoke
Dec 03 18:43:27.813 2013@LM_EMERGENCY@ (8808) OnDbgHelpErr: SymGetLineFromAddr64, GetLastError: 487 (Address: 0FFA6B99)
Dec 03 18:43:27.813 2013@LM_EMERGENCY@ (8808) 0FFA6B99 (ACEd): (filename not available): ace_thread_adapter
Dec 03 18:43:27.813 2013@LM_EMERGENCY@ (8808) f:\dd\vctools\crt_bld\self_x86\crt\src\threadex.c (314): _callthreadstartex
Dec 03 18:43:27.814 2013@LM_EMERGENCY@ (8808) f:\dd\vctools\crt_bld\self_x86\crt\src\threadex.c (297): _threadstartex
Dec 03 18:43:27.814 2013@LM_EMERGENCY@ (8808) OnDbgHelpErr: SymGetLineFromAddr64, GetLastError: 487 (Address: 75B1336A)
Dec 03 18:43:27.814 2013@LM_EMERGENCY@ (8808) 75B1336A (kernel32): (filename not available): BaseThreadInitThunk
Dec 03 18:43:27.814 2013@LM_EMERGENCY@ (8808) OnDbgHelpErr: SymGetLineFromAddr64, GetLastError: 487 (Address: 779C9F72)
Dec 03 18:43:27.814 2013@LM_EMERGENCY@ (8808) 779C9F72 (ntdll): (filename not available): RtlInitializeExceptionChain
Dec 03 18:43:27.814 2013@LM_EMERGENCY@ (8808) OnDbgHelpErr: SymGetLineFromAddr64, GetLastError: 487 (Address: 779C9F45)
Dec 03 18:43:27.814 2013@LM_EMERGENCY@ (8808) 779C9F45 (ntdll): (filename not available): RtlInitializeExceptionChain

然后查看之前写的程序,发现也是调用了ACE_Thread_Manager却不会出现崩溃的问题,对比了一下,发现之前写的程序用的是main函数而不是WinMain,在这里试了好久后,突然想到对于main函数,ACE会将其替换为ACE的main函数然后执行一系列初始化操作后再调用我们的main,那么会不会是因为由于ACE不会替换WinMain从而导致ACE中的一些初始化没有执行导致ACE_Thread_Manager崩溃呢?

google了一下,发现网上的说法是,如果是WinMain需要在开头手动调用
Init_ACE.h中的ACE::init(),试了一下果然不会崩溃了。

那么ACE自己的main函数中到底执行了什么操作呢?
查啊查发现主要执行以下操作(在OS_main.cpp中):
ACE::init ();
ACE_MAIN_OBJECT_MANAGER
int const i = this->run_i (ce_argv.argc (), ce_argv.argv ());
ACE::fini ();
return i;

原来如此!!!
至于ACE::init()到底做了什么初始化操作呢?请自行查看

1
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:19218次
    • 积分:420
    • 等级:
    • 排名:千里之外
    • 原创:24篇
    • 转载:0篇
    • 译文:0篇
    • 评论:3条
    文章分类
    最新评论