Browse Source

qt: medialib: fix race condition

If cancel() was called before the first lock was acquired in run(), then
cancel() would return immediately and run() would continue as if it was
not canceled (which could cause segfaults).

To avoid the problem, always set the "canceled" flag on cancel, so that
any future execution of run() will return immediately.

Note: we could alternatively track the "finished" state, and wait until
the task is finished on cancel(). However, if run() may not start
immediately (if the thread pool is full), this strategy would cause to
block on cancel() until run() is actually executed, which is
unnecessary.

Signed-off-by: Alexandre Janniaux <ajanni@videolabs.io>
pull/117/head
Romain Vimont 6 years ago
committed by Alexandre Janniaux
parent
commit
bf3397c83e
  1. 2
      modules/gui/qt/medialibrary/mlgenre.cpp

2
modules/gui/qt/medialibrary/mlgenre.cpp

@ -185,9 +185,9 @@ public:
void cancel()
{
QMutexLocker lock(&m_taskLock);
m_canceled = true;
if (!m_running)
return;
m_canceled = true;
m_taskCond.wait(&m_taskLock);
}

Loading…
Cancel
Save