[mythtv] [BUG?] Endless waiting for thread...

Anduin Withers awithers at anduin.com
Sat Mar 12 17:19:41 UTC 2005

> I'm not sure I see how.  If the ProcessRequestThreads are using tryLock
> waiting for something to appear in the queue they are not deadlocked,
> just looping.  And then the only other lock is on the readSocket for
> putting items into the queue.  As you said, the problem isn't locking
> per se but the behavior is such that the threadPool is starved so it
> seems to me the best answer is to alleviate the threadPool as it exists
> and put the onus on a command queue.  It isn't feasable to use tryLock
> when returning a thread to a pool, but it does work fine for a request
> thread for pulling commands out of the queue.

I believe the eventual answer is to abandon Qt's sockets wrapper, 
I tried calling the app event loop before the sleep, while this does get the
endConnection notification this isn't enough. I went a little further and it
actually isn't making it as far as I thought. There is a lock problem, only
in this case it is a QApplication lock. When the readSocket signal is called
the application lock is active, as ReadStringList locks the app while
waiting for data, there is a situation where all pool threads can be waiting
on the application lock, which will never be released as readSocket won't

The cure seems worse than the problem though (unlocking the app mutex in
readSocket and forcing the event loop to execute, or perhaps moving the lock
in ReadStringList).

My previous approaches to this problem have always been a bit too ambitious
for me to achieve in the amount of time I spend on mythtv. I do think a
better approach would be to break the socket stuff out, have the socket
portion of the server run in a thread (because threads are the answer to
everything, they aren't really but the Qt model and the way it is used
currently is hard to think about and harder to make work right) and when it
needed to serialize with the app have it post an event with a
synchronization object on it (so the app can notify it when done).

Anduin Withers

More information about the mythtv-dev mailing list