【问题标题】:AIX: Why does throwing an exception abort multithreaded code?AIX:为什么抛出异常会中止多线程代码?
【发布时间】:2010-09-23 06:07:50
【问题描述】:

当运行使用 -pthread 编译的代码时抛出 C++ 异常时,我们会中止。

平台:AIX 5.3 技术级别 8 编译器:gcc 3.4.6 链接器:AIX 链接器 1.65.2.4

测试代码:

// exception.cpp
#include <iostream>

class MyException
{
public:
        MyException(){}
        virtual ~MyException(){};
};

void gTest()
{
        throw MyException();
}

int main()
{
        try
        {
                gTest();
        }
        catch(MyException const & ex)
        {
                std::cout << "exception was caught" << std::endl;
        }

        return 0;
}


$ g++ exception.cpp
$ ./a.out
exception was caught
$ g++ -pthread exception.cpp
$ ./a.out
terminate called after throwing an instance of 'MyException'
IOT/Abort trap (core dumped)
$ gdb a.out
GNU gdb 6.0
Copyright 2003 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "powerpc-ibm-aix5.1.0.0"...
(gdb) run
Starting program: /home/leeder/except/a.out
terminate called after throwing an instance of 'MyException'

Program received signal SIGABRT, Aborted.
Switching to Thread 1
0xd0124834 in pthread_kill () from /usr/lib/libpthreads.a(shr_xpg5.o)
(gdb) bt
#0 0xd0124834 in pthread_kill () from /usr/lib/libpthreads.a(shr_xpg5.o)
#1 0xd01242a8 in _p_raise () from /usr/lib/libpthreads.a(shr_xpg5.o)
#2 0xd0359bdc in raise () from /usr/lib/libc.a(shr.o)
#3 0xd03b7efc in abort () from /usr/lib/libc.a(shr.o)
#4 0xd0ca1800 in __gnu_cxx::__verbose_terminate_handler() () at ../../.././libstdc++-v3/libsupc++/vterminate.cc:96
#5 0xd0ca1220 in __cxxabiv1::__terminate(void (*)()) (handler=0)
at ../../.././libstdc++-v3/libsupc++/eh_terminate.cc:43
#6 0xd0ca128c in std::terminate() () at ../../.././libstdc++-v3/libsupc++/eh_terminate.cc:53
#7 0xd0ca7cfc in __cxa_throw (obj=0x200084e8, tinfo=0xffffffff, dest=Cannot access memory at address 0xffffffff
)
at ../../.././libstdc++-v3/libsupc++/eh_throw.cc:80
#8 0x100008dc in gTest() ()
#9 0x100009f0 in main ()
(gdb)

有人见过类似的吗?

你认为升级到 gcc 4 会有帮助吗?

改用 IBM 的 xl 编译器怎么样?

谢谢。

【问题讨论】:

  • 听起来很奇怪……你试过其他编译器吗?
  • 我们将尝试 gcc 4.3.2,但我想看看其他人是否有经验。
  • 使用 g++ 4.8.3 在 AIX 6100-06 和 7100-01 上工作

标签: c++ exception gcc aix


【解决方案1】:

g++ 4.3.2 似乎可以解决这个问题。 xlC v10 也可以工作。

【讨论】:

    【解决方案2】:

    在 AIX 上试用了您的程序:

    操作系统级别-r

    5200-08

    使用 g++ --version

    g++ (GCC) 3.3.2

    g++ -o ex -pthread ex.cpp

    将导致在运行时找不到符号 (pthread_mutex_t)

    但是,如果您像这样构建它:

    g++ -o ex -lpthread ex.cpp

    效果很好。 我想这可能是正确的 pthread 库的链接问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-18
      • 2013-03-30
      • 1970-01-01
      • 2015-10-04
      • 1970-01-01
      相关资源
      最近更新 更多