2012-11-19 2 views
4

가능한 중복은 :
Why does this simple std::thread example not work?왜이 프로그램은 'std :: system_error'를 던집니까?

코드 :

#include <iostream> 
#include <thread> 

void f() 
{ 
    std::cout << "hi thread" << std::endl; 
} 

int main() 
{ 
    std::thread t(f); 
    std::cout << "hi" << std::endl; 
    t.join(); 
} 

문제 :

$ g++ -o thread_test thread_test.cpp -std=c++0x 
$ ./thread_test   
terminate called after throwing an instance of 'std::system_error' 
    what(): Operation not permitted 
Abortado 

"Abortado"이란 "중단"내가 내 로케일.

답변

9

당신은 pthread에 연결해야합니다

g++ -o thread_test thread_test.cpp -std=c++0x -lpthread 

libstdc++std::thread 구현 libpthread에 응용 프로그램을 연결하도록 요구, 당신은 스레드를 만들려고 할 때, 그렇지 않으면 그들이 std::system_error을 던질거야.

+4

누군가가 버그 보고서 나 전자 메일 체인 또는 누군가가 왜 링커 오류로 발생하지 않는지에 대한 정당성을 설명 할 수 있습니까? 그러면이 코드를 잡아 내야하는 링커 오류가 아닌 방법은 무엇입니까? –

+0

@Kevin 아주 흥미로운 질문입니다. 나는 온라인으로 답변을 찾을 수 없다. 누군가가 당신에게 힌트를 주는지를보기 위해, 단지 코멘트가 아닌 새로운 스레드에서 그 질문을하고 싶을지도 모른다. – mfontanini

관련 문제