I am fairly new to using mutexes seriously.
After implementing a few mutexes in various places, I realized that program execution hangs (not exit). I tried to debug it (in eclipse environment) but I couldn't reach a definite reason(or at least i don't know how to find one) However, I know now the program hangs when it tries to make a lock after a few iterations that makes a lock in the same place successfully.
here are some code:
void xxx::receiveModule(timeslice now)
{
//check if you have received anything in the incoming buffer
if(!isIncomingDirty())// <- has a mutex inside
{
return;
}
//...
}
bool &yyy::isIncomingDirty() {
boost::unique_lock< boost::shared_mutex > lock(*Communicator_Mutexes[2]));//<-this will cause hang after a few calls
return incomingIsDirty;
}
I dont know what behaviour a deadlock will show when it occurs. 1-is this a deadlock?
2-where would you check to look for the cause?
3-can recursive locking or nested locking of the same mutex cause such situation?
and this one may be off topic:
4-I exchange mutexes between classes to be used in their methods by different threads. is this a common practice? is such thing allowed?
thanks you very much for your comments and solutions