24,854
社区成员
发帖
与我相关
我的任务
分享
http://www.linuxdiyf.com/linux/16086.html
//main.cpp
#include <iostream>
#include <thread>
using namespace std;
void Test(){
for (auto i=0; i<100; ++i){
cout<<i<<endl;
}
}
auto main()->int{
thread t(Test);
t.join();
return 1;
}
编译参数:
g++ -std=c++1z -O3 -Wall -static main.cpp -o test -lpthreadSegmentation fault 通常不是库函数的问题,而是你代码问题造成的原因,即使在非静态编译下看似没问题也不足以说明你代码没问题
多线程需要加锁。