리뷰가 필요한 기본 샘플이 있습니다 (C++).부스트가 동일한 스레드에 대해 다중 잠금을 얻습니다.
PublicFunc() 함수와 PrivateFunc()이라는 함수가 있다고 가정 해 보겠습니다. 나는 그들을 신중하게 동기화하고 싶다. 그러나 PrivateFunc은 PublicFunc을 호출 할 수도 있습니다. 이는 같은 스레드에서 호출하는 것을 의미합니다. 이로 인해 블록이 생기고이를 해결하고 싶습니다.
mutable boost::mutex m;
void PublicFunc() {
m.lock();
//Here it blocks, but why?
//What I need is to get the lock if this func was called from PrivateFunc(), so exactly from the same thread.
//But! It should definitely block on calling PublicFunc from outside while we are for example in the 'OtherPrivateFunc'.
//Do some stuff
//this is not necessary
m.unlock();
}
void PrivateFunc() {
m.lock();
PublicFunc();
OtherPrivateFunc();
m.unlock();
}
어떤 뮤텍스 또는 잠금이 부스트 라이브러리에서 올바른 것입니까? 감사합니다.