wxConfig and access from multiple threads/processes

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
freudi74
In need of some credit
In need of some credit
Posts: 5
Joined: Fri Aug 30, 2019 9:03 am

wxConfig and access from multiple threads/processes

Post by freudi74 »

I haven't found any information in the documentation whether wxConfig and more specifically wxFileConfig is save to use in concurrent access situations, especially when the same config file is accessed by multiple processes.

I assume concurrent read()s should be OK, but what about write()s? What about read() while write() is occurring?

If it's not save, any suggestion how to easiest synchronize write accesses cross processes? Lock files? Or Windows named mutex?

FYI: My app is targetting Windows at this time, but still want to use file based config, not the registry based...
User avatar
doublemax
Moderator
Moderator
Posts: 19159
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxConfig and access from multiple threads/processes

Post by doublemax »

wxFileConfig is definitely not thread-safe. At the very least, you'd have to protect every access with a mutex/critical condition and call Flush() after each write access.
Use the source, Luke!
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4204
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxConfig and access from multiple threads/processes

Post by PB »

.ini files, just like any other files, being generally unsafe when coming to sharing among processes are one of the reasons they were replaced by Registry.
See e.g. bullets 3 and 4 here: https://devblogs.microsoft.com/oldnewth ... 0/?p=24383

But if your application is portable, I guess you must use them. AFAIK, wxWidgets does not have a named wxMutex, perhaps because some platforms may not have them (e.g., wxSingleInstanceChecker on Linux uses locked files instead of a mutex)
Post Reply