c++ - debian 和 std::thread c++ 的即时段错误

标签 c++ multithreading debian stdthread

遇到这个问题 - 在标题中..

我有这个代码:

#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])

我在网上搜索过,但没有找到合适的。

最佳答案

使用 g++ -std=c++0x -lpthread 编译。注意 pthread 之前的 l

关于c++ - debian 和 std::thread c++ 的即时段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12057525/

相关文章:

debian - W : Failed to fetch http://httpredir. debian.org/debian/dists/jessie-updates/main/binary-amd64/Packages 404 未找到

c++ - 无向图中的最长循环

c++ - 如何将连续输出存储为完整字符串?

c - 用于 win32/C 的线程生产者/消费者的阻塞队列

c++ - 来自多个线程的 std::cout

Java多线程网络,好还是坏?

linux - 自动启动服务失败

c++ - 未创建目标文件

c++ - 刚刚向 TMPing 介绍自己,发现了一个怪癖

linux - RTW_CMD_THREAD 负责什么?