PPC 中创建线程崩溃

问题描述 投票:0回答:3

我已经使用 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 ()

您能否建议我们是否缺少构建标志中的某些内容。

c++ linux powerpc
3个回答
0
投票

您的代码中有一个明显的错误

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

这里cout(流)是共享资源,你应该同步访问它。


0
投票

主要提示在这里:

Program received signal SIGILL, Illegal instruction.

您的编译器的默认代码生成设置似乎正在输出您的 CPU 不支持的指令。如果从 gdb 打印实际的错误指令,您可以获得有关问题的更多详细信息。尝试:

(gdb) x /i $pc

查看导致

SIGILL
的确切指令。

由于非法指令位于

__exchange_and_add
中,因此这很可能是原子存储指令之一。

要解决此问题,您可能需要告诉编译器为哪个 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

-1
投票

我尝试执行为 ppc 架构编译的相同示例。主机架构为x86_64。线程也存在一些问题。

@rajeshkb 你能告诉我你用哪个boost来更新它吗?

© www.soinside.com 2019 - 2024. All rights reserved.