【发布时间】:2012-08-21 14:49:29
【问题描述】:
遇到了这个问题 - 在标题中..
我有这个代码:
#include <thread>
#include <iostream>
void my_thread_func()
{
std::cout<<"hello"<<std::endl;
}
int main()
{
std::thread t(my_thread_func);
t.join();
}
取自网络。编译器选项 -pthread -std=gnu++0x (也试过-std=c++0x)我有段错误。一切都在 vmBox 上的 Debian 上。我之前已经启动了其他代码,并且它们有效。突然,我在所有工作应用程序中使用 std::thread 的线程出现了段错误。
编辑:这是来自 gdb:
(gdb) where
#0 0x00000000 in ?? ()
#1 0x08048dc9 in thread<void (*)()> (this=0xbffff3fc,
__f=0x8048b9f <my_thread_func()>) at /usr/include/c++/4.4/thread:129
#2 0x08048bea in main () at ../test.cpp:18
(当我使用 std::thread t(&ClassName::my_thread_func,ptr) 启动更高级的应用程序时,错误相同,但另一行 [thread:133])
我在网上搜索,但没有找到合适的。
【问题讨论】:
-
与 boost::thread 一起工作?什么版本的gcc?还有看看/usr/include/c++/4.4/thread:129怎么样?
-
我在 Ubuntu 11.04 上尝试过,对我来说效果很好。没有段错误。
-
g++ (Debian 4.4.5-8) 4.4.5 ,没有检查 boost
-
您是否收到“Pure virtual function called”消息?
-
@Wiciu 实际版本是 4.7。关于你的版本检查gcc.gnu.org/gcc-4.4/cxx0x_status.html
标签: c++ multithreading debian stdthread