스레드를 만들고 해당 클래스의 구성원으로 참조를 유지하려고 시도하고 스레드가 클래스의 메서드를 호출합니다. 코드는 다음과 같습니다.클래스 데이터 멤버로 스레드 만들기
EventQueue::EventQueue() {
this->dispatcherThread = std::thread(&EventQueue::dispatchEvent, std::ref(*this));
this->dispatcherThread.join();
}
QtCreator를 사용하여 빌드를 수행하고 있습니다. 이 오류가 발생합니다 :
/home/eventqueue.o:-1: In function
std::thread::thread<void (EventQueue::*)(), std::reference_wrapper<EventQueue> >(void (EventQueue::*&&)(), std::reference_wrapper<EventQueue>&&)': /usr/include/c++/4.9/thread:136: error: undefined reference to
pthread_create' :-1: error: collect2: error: ld returned 1 exit status
무엇이 문제입니까?
은이 게시물에 참조 하였다 Storing an std::thread object as a class member
그러나 나는 항상
당신은 pthread와 라이브러리에 링크해야
당신은 pthread''와 연결하지 않습니다. – Jarod42