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

Avoid recursive snatch lock acquisitions #5426

Merged
merged 4 commits into from
Mar 23, 2024

Conversation

SludgePhD
Copy link
Contributor

@SludgePhD SludgePhD commented Mar 22, 2024

Connections
Bug report: #5279

This PR is an alternative to #5400.

Description
Pass &SnatchGuard down to all functions needing it, instead of having them recursively acquire one.

This also adds some instrumentation to the SnatchLock API that will panic on any attempts to acquire it recursively (gated behind cfg(debug_assertions)). That should allow the test suite to catch any future misuse of the API, instead of silently making wgpu more deadlock-prone in multi-threaded applications.

Testing
cargo xtask test locally and on CI

Checklist

  • Run cargo fmt.
  • Run cargo clippy. If applicable, add:
    • --target wasm32-unknown-unknown
    • --target wasm32-unknown-emscripten
  • Run cargo xtask test to run tests.
  • Add change to CHANGELOG.md. See simple instructions inside file.

@SludgePhD SludgePhD force-pushed the avoid-recursive-snatch branch 2 times, most recently from d3d9643 to 315bbf3 Compare March 22, 2024 17:50
@SludgePhD SludgePhD marked this pull request as ready for review March 22, 2024 18:07
@SludgePhD SludgePhD requested a review from a team as a code owner March 22, 2024 18:07
Copy link
Member

@Wumpf Wumpf left a comment

Choose a reason for hiding this comment

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

Thank you very much for this fix!
Indeed not as nice to read as a solution than the recursive lock, but I think @jimblandy is right, this version is the way to go.
Extra thanks for adding the debug assertion in there to capture this sooner in the future.

Bunch of smaller things to fix up and then good to go!
Please also add a changelog entry about this fix.

wgpu-core/src/device/global.rs Outdated Show resolved Hide resolved
wgpu-core/src/device/queue.rs Outdated Show resolved Hide resolved
wgpu-core/src/device/resource.rs Outdated Show resolved Hide resolved
wgpu-core/src/snatch.rs Show resolved Hide resolved
wgpu-core/src/snatch.rs Outdated Show resolved Hide resolved
wgpu-core/src/snatch.rs Show resolved Hide resolved
Copy link
Member

@Wumpf Wumpf left a comment

Choose a reason for hiding this comment

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

lgtm, but changelog entry is still missing!

@Wumpf Wumpf merged commit 6b996dd into gfx-rs:trunk Mar 23, 2024
27 checks passed
@teoxoy teoxoy mentioned this pull request Jul 3, 2024
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

Successfully merging this pull request may close these issues.

2 participants