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

René J.V. Bertin rjvbertin at gmail.com
Fri Sep 29 11:35:40 CEST 2017


Hi,

I've been running into issues using adding and removing entries from QFSW in concurrent threads. This is in KDevelop while adding all directories of multiple projects (source trees) to a single QFSW instance per project. The app is somewhat complex so I think but am not entirely certain that the source trees are read on a single background thread; if I'm correct each QFSW instance is fed from a single thread only. (The QFSW instances are created and "slotted" on the main thread.)

The issues range from more or less severe lock-ups on Mac (the hard lock-ups occur in the FSEvents backend) to double-free crashes on Linux. I can only avoid them by using a single mutex that ensures that only 1 thread can use the class at a time.

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?

Thanks,
R.



More information about the Development mailing list