Threadsafe setState() with RTTransfer necessary?

Hi,
for the latest version of the SDK (3.7.3) there is a tutorial for how to use the new RTTransfer helper in order to make changes in setState() thread-safe. I’ve never been aware of this issue. Does the host actually call AudioEffect::setState() from a non-realtime thread? All other example plugins just update their internal values in setState() - so does that introduce a race condition there too?

Thanks in advance

setState is NOT thread safe and is not called from the real time thread. Of course this can depend on the host since it is the host doing the call. But since this call usually involves saving the state to storage, then it really should not be done on the real time thread and from my own experience it is not. I have not checked 3.7.3 yet (so I do not know about this RTTransfer class), but all examples provided with the (previous) SDKs are not thread safe…

There was a thread on this topic a while ago…

1 Like

Thanks @pongasoft. I was a bit confused that all examples should be “thread-unsafe” but the question you pointed to explains it all.
Thank you

The examples in the SDK are simple and the problem with undefined behaviour is only a real problem if your model consists of more complex data than just a few floating point parameters. For simplicity and readability some examples in the SDK will stay using a simpler setState method without solving the undefined behaviour but now you can use the SDK classes to takle this problem which was not the case before.

Yes, that totally makes sense.
Thanks for providing this easy-to-use solution.

I agree with keeping the examples simple. Since you have added a new helper RTTransfer it might be worth:

  • pointing out in the existing examples (comment or something like this) that it is kept simple for the sake of this example… but might not be what you want when you build a real device (and maybe referencing the tutorial?)
  • add an example that uses RTTransfer for a more concrete example of what you are supposed to do