다른 클래스의 서로 다른 인스턴스간에 하나의 클래스에서 뮤텍스를 공유하는 방법을 궁금합니다.클래스의 다른 인스턴스간에 mutex를 어떻게 공유합니까?
지금은 개인 멤버 변수로 부스트 뮤텍스와 condition_variable을 가진 클래스 인 Indexer가 있습니다. 내 메인에 Indexer 클래스의 auto_ptr을 만들고 다른 클래스 인 Robot의 인스턴스에 Indexer의 포인터를 전달합니다.
나는 다음과 같이 그렇게 :
std::auto_ptr<Indexer> index_service(new Indexer());
Robot a(*index_service.get());
Robot b(*index_service.get());
Robot c(*index_service.get());
로봇의 생성자는 다음과 같습니다 뮤텍스가 noncopyable 때문에, 내가 얻을
class Robot
{
public:
Robot(Indexer &index_service);
private:
Indexer index_service;
};
그러나 :
Robot(Indexer &index_service)
{
this->index_service = index_service;
}
로봇의 헤더처럼 보인다 오류.
mutex 및 condition_variable shared_ptrs를 만들려고했지만 예상치 못한 동작이 발생할 수 있음을 읽었습니다.
누군가가 나에게이/올바른 올바른 방법을 보여줄 수 있습니까?
감사합니다.
Robot 클래스에서 인덱서 유형의 변수를 갖고 있다고 생각하십니까? –