Is IComponent::getState()/setState() thread-safe?

Even with atomic values, if the state is comprised of more than one value, then I just don’t see how you make it thread safe IF there is no guarantee of when getState/setState are being called…

Here is a very simple example in my VST plugin: 2 variables define the state of the plugin. Each variable on its own is probably atomic.

 int fSwitchState; // 0 = A, B = 1
 bool fSoften;

In the process method:

...
  int32 numParamsChanged = inputParameterChanges.getParameterCount();
  for(int i = 0; i < numParamsChanged; ++i)
  {
    IParamValueQueue *paramQueue = inputParameterChanges.getParameterData(i);
    if(paramQueue != nullptr)
    {
      ParamValue value;
      int32 sampleOffset;
      int32 numPoints = paramQueue->getPointCount();

      // we read the "last" point (ignoring multiple changes for now)
      if(paramQueue->getPoint(numPoints - 1, sampleOffset, value) == kResultOk)
      {
        switch(paramQueue->getParameterId())
        {
          case kAudioSwitch:
            fSwitchState = value;
            break;

          case kSoftenSwitch:
            fSoften = value == 1.0;
            break;
        }
      }
    }
  }

And the setState method

  IBStreamer streamer(state, kLittleEndian);

  float savedParam1 = 0.f;
  streamer.readFloat(savedParam1);
  fSwitchState = savedParam1;

  bool savedParam2 = true;
  streamer.readBool(savedParam2);
  fSoften = savedParam2;

And the getState method

  IBStreamer streamer(state, kLittleEndian);
  streamer.writeFloat(fSwitchState);
  streamer.writeBool(fSoften);

If getState is called absolutely any time, then there might be a case when the 2 values are being read/assigned in the process method while they are being written to the streamer… so you could end up with fSwitchState having the new value while fSoften has the old one… and there you go, the state is written invalid. The fact that the 2 values are atomic is not enough.

How do you go about this if you do not use any locks? Or is there some form of guarantee in when and how getState/setState are being called?

Yan