-
Notifications
You must be signed in to change notification settings - Fork 105
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
Remove comment stating that thread-safe methods must also be realtime-safe #448
base: next
Are you sure you want to change the base?
Conversation
ce09fc4
to
c7a1ce6
Compare
so the intent was: thread safe functions can be called from the audio thread. i think your change would require us to use another type of marker [thread-safe; !audio] i agree this would be a useful change to the spec, but simply removing the comment is probably not the complete change. |
There are two kinds of correctness at play here, logical correctness and realtime correctness. The markers in the docs ( In this context, the We could go through and replace |
Yes you are correct we have overlapped audio thread with realtime safe Introducing a realtime safe marker would solve this but it then leaves two questions is a thread safe function which is not realtime safe safe to call from any thread? No. So we end up with the unsatisfying result that it is not safe to call a thread safe function from a thread is there any audio thread function which is not realtime safe? No. So do we double up the markers so we really have a four of things audio thread and the first and last would require those functions to meet realtime safety right now thread safe means the fourth and I think you are wanting to add the third category Not sure what change that would mean for the documentation though |
Oh and you said
The sentence you want to remove is the one which makes this false, which is why the sentence is there. The spec as written means a thread safe function is always realtime correct. |
Right, I want to remove the sentence, because requiring |
I'm proposing three categories of function with regard to logical correctness:
And then, separately, I'm proposing two categories of function with regard to realtime correctness:
In most cases, any function marked |
Yeah I get that (although Im not sure I agree on the first - I see no reason a midi event couldn’t make a plugin request a result: even though I would bounce to the ui thread for that myself ) but just removing the sentence causes other problems. Which is what we are trying to solve! |
But it seems the solution is really to either
wdyt? |
Another alternative would be to do away with thread safe altogether and use a combo of main thread audio thread concurrent safe and realtime safe on the apis which you could convince me of I bet too! |
So the thing I just can’t get over here is Q: “hey this function is marked thread safe what does that mean” you see why that’s a problem right? |
I’m becoming increasingly convinced that removing thread safe altogether and replacing it with concurrent safe and realtime safe is the way to go (with the implication that no api point is concurrent unless so marked and all audio thread are realtime safe unless marked) |
Basically our tags aren’t orthogonal enough Ugh you’ve raised a good problem even though I’m not crazy about your answer |
The reason I'm in favor of However, I can appreciate your argument that having
|
Yeah I like this approach but I think it removes some of the 'concurrency' safeness implicit in thread safe.
is i think what we mean. Or heck maybe even
where thread-safe implies any thread so realtime may be in play. |
I am against having |
yeah the problem with
hmm. like i said the problem you are trying to fix is correct. i'm just not sure we are stumbling exactly to the solution wonder if @abique @defiantnerd @Bremmers and other reviewers have some thoughts too |
As I mentioned in free-audio/clap-helpers#76, Clang 20 is introducing a RealtimeSanitizer with |
realtime is also non-allocating, no io, etc... of course! does nonblocking include those? can you malloc in a tagged file? but those sound super useful |
@baconpaul The documentation is here and here.
Yes, And here's the full set of constraints. It offers a lot of customizability for people using it - custom error handlers, several different runtime options, and various ways of suppressing errors for individual functions, function calls, or translation units at compile time or runtime. RtSan is not enabled by default - If CLAP API functions were marked with One thing I'm unsure of is whether there will be issues using the CLAP API in a C++ program when the API functions are not marked with |
Wow that sounds really useful |
I don't think this comment makes a whole lot of sense given the set of existing functions in the CLAP API which are marked
[thread-safe]
. For instance:clap_plugin_entry
:get_factory
clap_host_gui
:resize_hints_changed
,request_resize
,request_show
,request_hide
,closed
clap_plugin_factory
:get_plugin_count
,get_plugin_descriptor
,create_plugin
clap_preset_discovery_factory
:count
,get_descriptor
,create
Ultimately, thread safety and real-time safety are simply different concerns, and any given function can satisfy one, both or neither. E.g.,
std::mutex::lock
is thread-safe but not realtime-safe, andclap_plugin.process
is realtime-safe but not thread-safe. I would support the idea of introducing a separate[realtime-safe]
annotation, but it doesn't make sense for it to be conflated with[thread-safe]
.