Synchronizing multiple plugin instances writing to the same file

Hello there,

When a plugin allows for saving its state to a file (outside of the host DAW’s mechanisms), there seems to be a need to synchronize this when there’s a potential for multiple instances writing to the same file.
I noticed in PropertiesFile, an InterProcessLock allows for synchronizing the writing of properties, and this makes sense since the nature of the data written to this file might involve reacting to multiple simultaneous programmatic events. In the previous scenario, file saving can only be done by user-actions, which in practice should mean that directing multiple instances to save to the same file should be physically impossible.
This brings me to a few questions:

  • Is it even necessary to synchronize multiple plugin instances from writing to the same file for this basic use case ?
  • When using JUCE objects (such as TemproraryFile) to write files, is there still potential for data race from another plugin instance?
  • What are the conventional/practical approaches for synchronizing file objects from multiple instance writes ? On top of normal locks, should these approaches also involve InterProcessLocks ?

I think this question is one of the “in 99% you should be fine” type.

a) it is unlikely for someone to parallelise gathering the individual plugin states. But it is a valid optimisation, so it might happen at some point.
b) in most hosts all plugins run in the same process, so a normal CriticalSection would work, but in hosts that spawn a separate process for each plugin (AUv3 and Reaper optionally), it would fail silently.

I would try to have it loosely coupled to avoid that common file, but maybe that is not an option.
Maybe something to put on the radar and fix it once it becomes a problem. Or if PropertiesFile is an option, using that InterProcessLock, that is already present sounds like a sane approach.

Just my 2 pennies

1 Like

Thanks for the info, my thinking is similar here. Was also unaware of the AUv3 separate process situation. AUv3 is probably going to be my main target for the plugin version so this is very good info.