|
本帖最后由 chennut0802 于 2011-11-19 13:17 编辑
大家好,我运行ACE库自带的例子,具体代码如下:- #include "ace/Reactor.h"
- #include "ace/Service_Config.h"
- #include "ace/OS_main.h"
- class Timeout_Handler : public ACE_Event_Handler
- {
- public:
- Timeout_Handler (void)
- : count_ (0) {}
-
- virtual int handle_timeout (const ACE_Time_Value &tv,
- const void *arg)
- {
- ACE_DEBUG ((LM_DEBUG,
- "%d timeout occurred for %s./n",
- ++count_,
- (char *) arg));
- return 0;
- }
- private:
- int count_;
- };
- int
- ACE_TMAIN (int, ACE_TCHAR *[])
- {
- Timeout_Handler handler;
- // 每隔1秒执行一次,延迟1秒才开始计时
- ACE_Time_Value bar_tv (1);
- ACE_Reactor::instance ()->schedule_timer (&handler,
- (void *) "Bar",
- bar_tv,
- bar_tv);
- // 每隔1秒执行一次,延迟1秒才开始计时
- ACE_Time_Value foo_tv (1);
- ACE_Reactor::instance ()->schedule_timer (&handler,
- (void *) "Foo",
- foo_tv,
- foo_tv);
- // 设置事件处理超时为12秒
- ACE_Time_Value run_time (12);
- if (ACE_Reactor::run_event_loop(run_time) == -1)
- ACE_ERROR_RETURN ((LM_ERROR, "%p./n", "main"), -1);
- return 0;
- }
复制代码 运行的结果:
1 timeout occurred for Bar.
2 timeout occurred for Foo.
3 timeout occurred for Bar.
4 timeout occurred for Foo.
5 timeout occurred for Bar.
6 timeout occurred for Foo.
7 timeout occurred for Bar.
8 timeout occurred for Foo.
9 timeout occurred for Bar.
10 timeout occurred for Foo.
11 timeout occurred for Bar.
12 timeout occurred for Foo.
13 timeout occurred for Bar.
14 timeout occurred for Foo.
15 timeout occurred for Bar.
16 timeout occurred for Foo.
17 timeout occurred for Bar.
18 timeout occurred for Foo.
19 timeout occurred for Bar.
20 timeout occurred for Foo.
21 timeout occurred for Bar.
22 timeout occurred for Foo.
23 timeout occurred for Bar.
24 timeout occurred for Foo.
之后出现错误“TestACE.exe 中的 0xabababab 处未处理的异常: 0xC0000005: 读取位置 0xabababab 时发生访问冲突”。
请问4个问题:
1.以上的错误是有什么引起的?
2.在使用ace库的时候,入口函数main与ACE_TMAIN有什么不同呢?
3.为什么没有调用ACE::init();与ACE::fini();程序还能运行呢?
4.开源软件如ace,为什么不直接把lib和头文件发布出来,需要用户自己编译呢?
请大家分别回答以上问题,谢谢! |
|