Deadlock with RO/RW locks and OpalMixerEndPoint::m_infoMutex
Brought to you by:
csoutheren,
rjongbloed
One thread simply tries to get RW lock on OpalCall.
Another thread gets ReadOnly lock on the OpalCall and calls OpalManager::MakeConnection -> OpalMixerEndPoint::MakeConnection, and tries to lock m_infoMutex there:
PWaitAndSignal mutex(m_infoMutex);
So thread 1 wait for the thread 2, thread 2 waits for the thread 3, and thread 3 waits for the thread 1.
Why does the thread 3 wait for the thread 1? Thread 1 simply waits for the RW lock, it doesn't have it yet.
It seems like the RO lock blocks other RO locks. I'll try the revision without std::atomic support.
The same issue with rev. 32815.
We've found that the bug is with PTLIB RW locks.
We'll create a new ticket with test code.
This is just a form of deadlock, and not really caused by the ReadWriteMutex implementation. That implementation is "text book", has been used for over a decade, and I am EXTREMELY unwilling to change anything significant in it. If it has the limitation you have indicated, then so be it.
I have examined several implementations and algorithms for read/write mutexes and they all have the same problem. Bottom line is this a variant of the A/B, B/A locking issue. So, is up to the user of the PReadWriteMutex to avoid.
I have tweaked the code to hopefully avoid the problem.