[Qt-interest] How to stop threads started by QFileSystemModel (QFileInfoGatherer, QWindowsFileSystemWatcherEngine)?

Thiago Macieira thiago.macieira at trolltech.com
Thu Aug 20 15:47:53 CEST 2009


Em Quinta-feira 20 Agosto 2009, às 13:10:02, Niels Dekker - no return address 
escreveu:
> Our code basically does:
> 
>   QFileSystemModel* fileSystemModel = new QFileSystemModel();
>   treeView->setModel(fileSystemModel);
> 
> Within the constructor of QFileSystemModel, a thread is created
> ('QFileInfoGatherer'). During the lifetime of fileSystemModel, some
> other threads are created, including 'QWindowsFileSystemWatcherEngine'.
> Unfortunately the destructor of QFileSystemModel doesn't delete those
> threads. Is that a bug?

Yes.

The destructor does delete the thread:

QFileInfoGatherer::~QFileInfoGatherer()
{
    mutex.lock();
    abort = true;
    condition.wakeOne();
    mutex.unlock();
    wait();
}

However, the "abort" variable is not declared volatile. The thread may never 
notice that the variable changed asynchronously, so the optimiser may remove 
the check altogether.

But if that happened, then wait() would block forever (well, for 49.7 days). 
You'd have noticed that.

So my conclusion is that the thread is stopped.

> Anyway, it appears that those threads cause a crash of our application,
> because they keep running, even when qApp is destructed and Qt's DLL's
> are unloaded. Is there a way to stop the threads created by
> QFileSystemModel?

The code tries to stop them

-- 
Thiago Macieira - thiago.macieira (AT) nokia.com
  Senior Product Manager - Nokia, Qt Development Frameworks
     Sandakerveien 116, NO-0402 Oslo, Norway

Qt Developer Days 2009 | Registration Now Open!
Munich, Germany: Oct 12 - 14     San Francisco, California: Nov 2 - 4
      http://qt.nokia.com/qtdevdays2009
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090820/b31c4ec7/attachment.bin 


More information about the Qt-interest-old mailing list