Need help debugging deadlocked mutex
I have a dead mutex lock in the following code:
CRegistry::CRegistry()
{
pthread_mutex_init(&_Mutex, NULL);
}
CRegistry::~CRegistry()
{
pthread_mutex_destroy(&_Mutex);
}
MR_RESULT CRegistry::Register(const REGISTRY_KEY &Id, const REGISTRY_ITEM &Item)
{
pair<REGISTRY::iterator, bool> Result;
pthread_mutex_lock(&_Mutex);
Result = _Registry.insert(pair<REGISTRY_KEY, REGISTRY_ITEM>(Id, Item));
pthread_mutex_unlock(&_Mutex);
if (Result.second == true)
return MR_RESULT_OK;
else
return MR_RESULT_ERROR;
}
MR_RESULT CRegistry::UnRegister(const REGISTRY_KEY &Id)
{
REGISTRY::size_type Result;
pthread_mutex_lock(&_Mutex);
Result = _Registry.erase(Id);
pthread_mutex_unlock(&_Mutex);
if (Result == 1)
return MR_RESULT_OK;
else
return MR_RESULT_ERROR;
}
_Mutext
is a member of the class and is not used anywhere else in your code. At some point, I see that a thread is stuck trying to lock an already locked mutex.
There are both real-time and non-real-time threads that block the mutex. I understand that there might be a preemptive inversion, but how can this lead to blocking?
+3
source to share
2 answers