Improve thread safety of resource loading #88561
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
During resource loading, including threaded loading, certain resources want to emit a
changed
signal. Since most of theObject
API, including signals, is not thread-safe, there's the risk of this causing issues. I've actually seen it happening, but I can't be sure if not getting them anymore is due to this fix.This PR will defer any emissions of that kind involved in loading that happen on a non-main thread. UPDATE: Bear in mind that during threaded loading, deferred calls are even more deferred, queued in a thread-specific call queue, until the resource is done loading, then flushed on the main thread.
UPDATE 2: An alternative would be letting
Object
itself defer signal-related calls during loads. However, I'm a bit afraid of adding a check there is too heavy for what so far seem to be few cases (more to discover, likely). Additionally, maybe at some pointObject
has to be made entirely thread-safe due to popular demand or something, and patches like this are not needed anymore.