KConfig race condition?

David Faure faure at kde.org
Mon Apr 19 18:39:48 BST 2004


On Monday 19 April 2004 19:16, Rob Kaper wrote:
> I'm having a problem where two applications want to update KConfig at the
> same time. Both application instances receive a notification to store a key
> (a cookie*), but it has happened where the save of the second application
> undid the change by the first. Should I reload the configuration always
> before saving it (seems like that still wouldn't guarantee success) or is
> there a proper way?
>
> One solution would be if KConfig, when saving its configuration, kept
> entries in the file it doesn't have itself, only removing items that were
> specifically removed by the application.

KConfig already reparses the config file before saving (if its timestamp is 
more recent than the last save from this process), and merges the two
(the in-process dirty entries with the on-disk config file).
See KConfigINIBackEnd::sync().

But in your case both processes can end up saving at the same time anyway.
I think you need real locking (somehow).

-- 
David Faure, faure at kde.org, sponsored by Trolltech to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).




More information about the kde-core-devel mailing list