以下代码在 rasberry pi mod2 系统上的 Rasbian 发行版中导致总线错误。
#include <thread>
#include <iostream>
class bar {
public:
void startFoo() {
std::thread t(&bar::foo, this); //bus error because of this line
t.join();
}
void foo() {
std::cout << "hello from member function" << std::endl;
}
};
int main()
{
bar b;
b.startFoo();
return 0;
}
此链接指出,当您的处理器甚至无法尝试请求的内存访问时,就会发生总线错误。但是在我的代码中,我正在线程中访问类自己的成员函数。我无法说明它是如何导致总线错误的。有人可以澄清一下吗?PS 源代码在 x86 PC 上运行的 Ubuntu 操作系统上交叉编译,二进制文件在 Rasberry pi (ARM) 上进行了测试。