Browse files

Fix hang in applications when threadpool thread fails to run.

In the event that a thread pool threads fails to start do not leave it
in the list of running threads which can lead to us waiting
indefinitely for it to finish in MThreadPool::waitForDone(). The fix
is to immediately remove the thread from the list of running threads
if IsRunning() is false immediately after calling start() - see
start() in qthread-unix.cpp. N.B. IsFinished() is false in this
scenario because the thread never started.

When this occurs, either because we've hit the system thread limit or
we've run out of memory QThread (on unix/linux) will print:
"QThread::start: Thread creation error: Resource temporarily

Shortly afterwards the thread calling MThreadPool::waitForDone() would
hang, in the case of the frontend this may be the UI thread in the
MythImage destructor.
  • Loading branch information...
stuartm committed Jun 2, 2013
1 parent c8a3eed commit 10c80db8b40c1f2f0a37dc7bc51b1885963290f5
Showing with 14 additions and 1 deletion.
  1. +14 −1 mythtv/libs/libmythbase/mthreadpool.cpp
@@ -382,7 +382,20 @@ bool MThreadPool::TryStartInternal(
thread->SetRunnable(runnable, debugName, reserved);
return true;
if (thread->isRunning())
return true;
// Thread failed to run, OOM?
// QThread will print an error, so we don't have to
if (reserved)
return false;

0 comments on commit 10c80db

Please sign in to comment.