Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-atomics read and written on different threads? #39

Open
cubicvoid opened this issue Dec 17, 2023 · 1 comment
Open

Non-atomics read and written on different threads? #39

cubicvoid opened this issue Dec 17, 2023 · 1 comment

Comments

@cubicvoid
Copy link

Thanks for this project, it's really helpful in understanding parameter values vs modulation! I did find a potential conflict between the parameter handling and the CLAP spec. Defining your parameter values you have:

    // These items are ONLY read and written on the audio thread, so they
    // are safe to be non-atomic doubles. We keep a map to locate them
    // for parameter updates.
    double unisonCount{3}, ...

but it seems like these are also read on the main thread. They're read (via pointers in the paramToValue map) from paramsValue(), implementing clap_plugin_params.get_value:

/// The host can at any time read parameters' value on the [main-thread] using
/// @ref clap_plugin_params.value().
...
   // Gets the parameter plain value.
   // [main-thread]
   bool (*get_value)(const clap_plugin_t *plugin, clap_id param_id, double *value);

This looks to me like these should be atomics, or maybe use cached values when accessing from get_value. Perhaps I'm misunderstanding something about the spec or the contextual assumptions (maybe there's some reason get_value is never concurrent to process)? But I was specifically looking for examples of thread-safe parameter handling in get_value so this stood out to me.

@baconpaul
Copy link
Collaborator

No i think you are correct. Those should be atomics, or there should be a cache which is atomically updated at the end of process indeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants