In the following code, I get an ASSERT in unlock (), because lockingThreads (a QList<QThread*>) does not contain the unlocking (current) thread.
Examining lockingThreads, I find an "ntdll" thread that I have no idea what it does and only disassembly can be accessed which doesn't provide useful information.
The problem is very hard to reproduce, so thanks for any hint (probably a stupid twist in this logic).
Edit: the mutex is recursive.
MyMutex::MyMutex (QMutex::RecursionMode mode)
: QMutex (mode)
, lockCount (0)
{
}
MyMutex::~MyMutex ()
{
ASSERT (lockingThreads.isEmpty ());
}
void MyMutex::lock ()
{
lockCount++;
#if MYDEBUG
// grab thread before lock so we can identify it if it deadlocks here
QThread* thread = QThread::currentThread ();
if (!isRecursive ())
{
ASSERT (!lockingThreads.contains (thread));
if (!lockingThreads.contains (thread))
lockingThreads += thread;
}
else
lockingThreads += thread;
#endif
QMutex::lock ();
}
void MyMutex::unlock ()
{
#if MYDEBUG
QThread* thread = QThread::currentThread ();
ASSERT (lockingThreads.contains (thread));
lockingThreads.removeOne (thread);
if (lockingThreads.contains (thread) && !isRecursive ())
ASSERTFALSE;
#endif
QMutex::unlock ();
lockCount--;
}