[Interest] QFileSystemWatcher malfunctioning

Bo Thorsen bo at fioniasoftware.dk
Thu Jan 12 22:13:48 CET 2012


Den 12-01-2012 14:56, Atlant Schmidt skrev:
> All:
>
>> With this class you just do this:
>>
>> {
>>      SignalBlocker blocker(watcher);
>>      modifyTheFile();
>> }
>
>    It seems to me that there's a race condition here.
>    Unless you're taking steps to deliberately lock-out
>    other processes from modifying the file, then they
>    could slip in immediately before or after you modify
>    the file and you would never know they'd been there
>    because you have the signal blocked.

True. But if you modify the file, you have a race condition anyway, 
since you don't know if that was done before or after you do this. You 
might not get the modified signal before you change the file contents.

If you're after a fool proof system, don't block the filewatcher and 
read it after your own changes, and check that the contents hadn't been 
changed before you do it. Or use a database.

Bo Thorsen,
Fionia Software.

-- 

Expert Qt and C++ developer for hire
Contact me if you need expert Qt help
http://www.fioniasoftware.dk



More information about the Interest mailing list