[問題] thread

看板C_and_CPP (C/C++)作者 (家家)時間12年前 (2014/01/16 19:46), 編輯推噓1(102)
留言3則, 3人參與, 最新討論串2/2 (看更多)
開發平台(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
g++ -std=c++11 multithread.cpp -o mul -lpthread
01/16 20:12, 1F

01/16 20:15, , 2F
-pthread
01/16 20:15, 2F

01/16 20:21, , 3F
謝謝!!!!!
01/16 20:21, 3F
文章代碼(AID): #1IryPyqP (C_and_CPP)
討論串 (同標題文章)
文章代碼(AID): #1IryPyqP (C_and_CPP)