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

Batch of fixes for WorkerThreadPool and ResourceLoader (safe set) #94526

Merged
merged 4 commits into from
Jul 19, 2024

Conversation

RandomShaper
Copy link
Member

@RandomShaper RandomShaper commented Jul 19, 2024

Extracted from #94169. See discussion there for details.


Re-add resource thread-safety measures

These deferring measures were added to aid threaded resource loading in being safe.

They were removed as seemingly unneeded, but it seems they are needed so resources involved in threaded loading interact with others only after "sync points".


WorkerThreadPool: Fix wrong sync logic breaking task map integrity


Fixup recent changes to threading concerns

ResourceLoader:

  • Fix invalid tokens being returned.
  • Remove no longer written ThreadLoadTask::dependent_path and the code reading from it.
  • Clear deadlock hazard by keeping the mutex unlocked during userland polling.

WorkerThreadPool:

  • Include thread call queue override in the thread state reset set, which allows to simplify the code that handled that (imperfectly) in the ResourceLoader.
  • Handle the mutex type correctly on entering an allowance zone.

CommandQueueMT:

  • Handle the additional possibility of command buffer reallocation that mutex unlock allowance introduces.

ResourceLoader: Fix sync issues with error reporting

This is about not letting the resource format loader set the error code directly on the task anymore. Instead, it's stored locally and assigned only when it is right to do so.

Otherwise, other tasks may see an error code in the current one before it's state having transitioned to errored. While this, besides the technically true data race, may not be a problem in practice, it causes surprising situations during debugging as it breaks assumptions.


These deferring measures were added to aid threaded resource loading in being safe.

They were removed as seemingly unneeded, but it seems they are needed so resources involved in threaded loading interact with others only after "sync points".
ResourceLoader:
- Fix invalid tokens being returned.
- Remove no longer written `ThreadLoadTask::dependent_path` and the code reading from it.
- Clear deadlock hazard by keeping the mutex unlocked during userland polling.

WorkerThreadPool:
- Include thread call queue override in the thread state reset set, which allows to simplify the code that handled that (imperfectly) in the ResourceLoader.
- Handle the mutex type correctly on entering an allowance zone.

CommandQueueMT:
- Handle the additional possibility of command buffer reallocation that mutex unlock allowance introduces.
This is about not letting the resource format loader set the error code directly on the task anymore. Instead, it's stored locally and assigned only when it is right to do so.

Otherwise, other tasks may see an error code in the current one before it's state having transitioned to errored. While this, besides the technically true data race, may not be a problem in practice, it causes surprising situations during debugging as it breaks assumptions.
Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIWAGOSu1!

Footnotes

  1. Taking It With A Grain Of Sugar, sweet sweet safe subset 😌

Copy link
Member

@AThousandShips AThousandShips left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These look reasonable

@akien-mga akien-mga merged commit 293c0f7 into godotengine:master Jul 19, 2024
18 checks passed
@akien-mga
Copy link
Member

Thanks!

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

Successfully merging this pull request may close these issues.

bytes_to_var_with_objects fails to decode custom classes on threads in v4.3.beta3
3 participants