MythTV  master

Framework for managing threads. More...

Collaboration diagram for MThreadPool:


class  MThread
 This is a wrapper around QThread that does several additional things. More...
class  MThreadPool

Detailed Description

Framework for managing threads.

Commit 47d67e6722 added two new classes MThread and MThreadPool to be used instead of QThread and QThreadPool. These mirror the API's of the Qt classes but also add a requirement for a QString naming the thread or naming the runnable which are used for debugging. These wrappers also make sure mysql connections are torn down properly and have a number of safety checks and assurances. The destructor for MThread also makes sure that a thread has stopped running before we allow the QThread to be deleted. And MThreaPool makes sure all it's threads have stopped running. MThread has a Cleanup() method that attempts to shut down any threads that are running, it only works for threads that exit on a call to exit(), which includes any threads using the Qt event loop. It will also print out the names of the threads that are still running for debugging purposes.

MThread has one special constructor. It takes a QRunnable* and runs it instead of the Qt event loop in the default run() implementation. Unlike MThreadPool and QThreadPool, MThread does not delete this runnable when it exits. This allows you to run something with less boilerplate code. Just like with QThread in Qt4 it really is better to use the Qt event loop rather than write your own. As you don't use the Qt event loop QObject deleteLater's are not executed until the thread exits, Qt events and timers do not work making Qt networking classes misbehave and signals/slots are generally unsafe. However, many of the threads with event loops in MythTV were written before Qt allowed an event loop outside the main thread so this syntactic sugar just lets us handle that with less lines of code.

There are a few other differences with respect to Qt's classes other than requiring a name.