[問題] thread
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
Linux
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
無
問題(Question):
最近開始學用thread,在網路上找了一些範例,
執行後卻出現Segmentation fault (core dumped),不知道是不是我忽略了什麼
範例來源: http://ppt.cc/1bM6
程式碼(Code):(請善用置底文網頁, 記得排版)
#include <iostream>
#include <thread>
using namespace std;
void test_func()
{
// do something
double dSum = 0;
for( int i = 0; i < 10000; ++ i )
for( int j = 0; j < 10000; ++ j )
dSum += i*j;
cout << "Thread: " << dSum << endl;
}
int main( int argc, char** argv )
{
// execute thread
thread mThread( test_func );
// do somthing
cout << "main thread" << endl;
// wait the thread stop
mThread.join();
return 0;
}
編譯: g++ -std=c++0x multithread.cpp -o mul
執行: ./mul
結果: Segmentation fault (core dumped)
麻煩板上大大幫我解答了,謝謝 :)
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.113.112.33
→
01/16 20:12, , 1F
01/16 20:12, 1F
推
01/16 20:15, , 2F
01/16 20:15, 2F
→
01/16 20:21, , 3F
01/16 20:21, 3F
討論串 (同標題文章)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章