문제

-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 컴파일러로 전환하는 것은 어떻습니까?

감사.

도움이 되었습니까?

해결책 2

G ++ 4.3.2는이 문제에 대해 잘 작동하는 것 같습니다. 또한 XLC V10은 작동합니다.

다른 팁

AIX에서 프로그램을 시도했습니다.

Oslevel -r

5200-08

g ++ -버전

G ++ (GCC) 3.3.2

g ++ -o ex -pthread ex.cpp

런타임에서 찾을 수없는 기호가 발생합니다 (pthread_mutex_t)

그러나 당신이 그것을 만들면 :

g ++ -o ex -lpthread ex.cpp

예상 효과로 잘 작동합니다. 이것은 올바른 pthread 라이브러리의 링크 문제 일 수 있다고 생각합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top