2016-06-01 7 views
0

以下のプログラムのビルド実行可能ファイルはPPCツールチェーンを使用しています。PPCのスレッド作成のクラッシュ

ツールチェーンの詳細: のpowerpc-WRS-のlinux-gnuの-G ++(ウインドリバーのLinuxのSourcery G ++ 4.4A-341)4.4.1

私たちは、コンパイル時に-pthread含まれており、リンクする-lpthreadています。 -lrtと-ldlフラグも使用しています。あなたは私たちは、ビルドのためのフラグで何かが欠けている提案してくださいすることができ

#include <string> 
#include <iostream> 
#include <thread> 

using namespace std; 

// The function we want to execute on the new thread. 
void task1(string msg) 
{ 
    cout << "task1 says: " << msg; 
} 

int main() 
{ 
    // Constructs the new thread and runs it. Does not block execution. 
    thread t1(task1, "Hello"); 

    // Makes the main thread wait for the new thread to finish execution 
    // therefore blocks its own execution. 
    t1.join(); 
} 

プログラムを実行している間は

Program received signal SIGILL, Illegal instruction. 
0x10000e30 in __gnu_cxx::__exchange_and_add(int volatile*, int)() 
(gdb) bt 
#0 0x10000e30 in __gnu_cxx::__exchange_and_add(int volatile*, int)() 
#1 0x10000f14 in __gnu_cxx::__exchange_and_add_dispatch(int*, int)() 
#2 0x10001960 in std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release()() 
#3 0x100016ac in std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count()() 
#4 0x100013ac in std::__shared_ptr<std::thread::_Impl_base, (__gnu_cxx::_Lock_policy)2>::~__shared_ptr()() 
#5 0x100013e8 in std::shared_ptr<std::thread::_Impl_base>::~shared_ptr()() 
#6 0x100014c0 in std::thread::thread<void (&)(std::basic_string<char, std::char_traits<char>, std::allocator<char> >), char const (&) [6]>(void (&&&)(std::basic_string<char, std::char_traits<char>, std::allocator<char> >), char const (&&&) [6])() 
#7 0x10000fd4 in main() 

以下のようにクラッシュを取得しています。

答えて

0

リソース共有されているあなたのコード

ここ
cout << "task1 says: " << msg; 

COUT(ストリーム)内の1つの明白なバグがあり、あなたはそれへのアクセスを同期する必要があります。

+0

メッセージなしでcoutを試しても、同じエラーが表示されます。それは本当の問題ではないようです。 – rajeshkb

+0

g ++ -std = C++ 11 -pthread -o main main.cpp、main.cppはソースファイル名 –

+0

C++ 11のサポートはありません。私たちは、PPCのスレッディングに問題があるように見えました。私たちはブーストで更新し、今は問題ありません。ありがとうございました。 – rajeshkb

0

主なヒントはここにある:

Program received signal SIGILL, Illegal instruction. 

あなたのコンパイラのデフォルトのコード生成の設定がご使用のCPUでサポートされていない指示を出力しているように見えます。 gdbからの実際のフォールト命令を印刷すると、その問題の詳細が得られます。試してください:

(gdb) x /i $pc 

SIGILLを引き起こす正確な指示を参照してください。

違法命令が__exchange_and_addにあるため、これはアトミックな格納命令の1つになる可能性があります。

この問題を解決するには、コンパイラに命令を生成するCPUを教えてください。これは引数-mcpu=で行うことができます。無効なCPU指定子を指定した場合、gccは使用可能なCPUタイプを出力します:

$ powerpc64le-linux-gnu-gcc -mcpu=? 
powerpc64le-linux-gnu-gcc: error: unrecognized argument in option ‘-mcpu=?’ 
powerpc64le-linux-gnu-gcc: note: valid arguments to ‘-mcpu=’ are: 401 403 405 405fp 440 440fp 464 464fp 476 476fp 505 601 602 603 603e 604 604e 620 630 740 7400 7450 750 801 821 823 8540 8548 860 970 G3 G4 G5 a2 cell e300c2 e300c3 e500mc e500mc64 e5500 e6500 ec603e native power3 power4 power5 power5+ power6 power6x power7 power8 power9 powerpc powerpc64 powerpc64le rs64 titan 
powerpc64le-linux-gnu-gcc: fatal error: no input files 
関連する問題