나는 잠금과 뮤텍스의 차이에 대해 매우 혼란 스럽다. 부스트 문서에서는 말한다"뮤텍스"와 "락"의 차이점은 무엇입니까?
잠금 유형
- 클래스 템플릿 lock_guard
- 클래스 템플릿 unique_lock
- 클래스 템플릿 shared_lock
- 클래스 템플릿 upgrade_lock
- 클래스 템플릿 upgrade_to_unique_lock
- 뮤텍스 관련 클래스 scoped_tr y_lock
뮤텍스 유형
- 클래스 뮤텍스
- 으로 typedef가 try_mutex
- 클래스 timed_mutex
- 클래스 recursive_mutex
- 으로 typedef의 recursive_try_mutex
- 클래스 recursive_timed_mutex
- 은 다른 기사에서 클래스 shared_mutex
, 나는
boost::shared_mutex _access;
void reader()
{
boost::shared_lock<boost::shared_mutex> lock(_access);
// do work here, without anyone having exclusive access
}
void conditional_writer()
{
boost::upgrade_lock<boost::shared_mutex> lock(_access);
// do work here, without anyone having exclusive access
if (something) {
boost::upgrade_to_unique_lock<boost::shared_mutex> uniqueLock(lock);
// do work here, but now you have exclusive access
}
// do more work here, without anyone having exclusive access
}
업데이트 질문, 다음과 같은 기능을 참조
- 사람이 "뮤텍스"와 "사이에 약간의 설명을 제공 할 수 자물쇠"?
- shared_mutex에 대해 shared_lock을 생성해야합니까? unique_lock을 shared_mutex으로 만들면 어떻게됩니까?
- 아니면이 뮤텍스에 대한 shared_lock를 작성하는 경우, 그것은 뮤텍스을 의미 하는가는 여러 스레드간에 공유 할 수 없습니다?
내 기사 "뮤텍스는 어떻게 작동합니까?" 도움이됩니다 : http://mortoray.wordpress.com/2011/12/16/how-does-a-mutex-work-what-does-it-cost/ –
새로운 질문입니다. 새로운 질문으로 그들에게 질문해야합니다. 이미 존재하는 질문에 후속 조치를 추가하지 마십시오. 또한 Boost의 문서에는이 모든 내용이 들어 있습니다. –