[Development] Should QFileSystemWatcher be thread-safe? (Qt 5.8.0)

Konrad Rosenbaum konrad at silmor.de
Fri Sep 29 11:49:32 CEST 2017


Hi,

On Fri, September 29, 2017 11:35, René J.V. Bertin wrote:
> I've been running into issues using adding and removing entries from QFSW
> in concurrent threads.
[cut]
> The QFSW documentation only mentions the class is reentrant. Is QFSW
> supposed to be thread-safe (at least at the class level), on all
> platforms? Or do we have to provide our own protection mechanisms if we
> want to use the class this way?

In the Qt documentation (and most other sane docu) "reentrant" means the
class can be used on different threads, but each instance must be
restricted to a single thread. You can have different instances on
different threads.

Actually documenting it as "thread safe" would imply that even instances
can be shared across threads. This is much harder to implement for (I
believe) obvious reasons.

This is why you were able to solve the problem with a Mutex: you ensured
that the instance was only used by one instance at a time.

Another way is to explicitly use Qt::QueuedConnection to feed the QFSW or
to untangle your code to ensure each QSFW is only visible from one thread.


   Konrad




More information about the Development mailing list