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

GetMappedRange is safe to call anytime #487

Merged
merged 2 commits into from
Jan 8, 2025

Conversation

kainino0x
Copy link
Collaborator

I think we can guarantee this.

From #481 (comment):

@lokokung:
Do you think "always unsafe" would be too pessimistic? I'm wondering if we could say "potentially unsafe"? (Mainly I'm thinking about getMappedRange calls in MapAsync callback which would be nice to use in spontaneous mode)

@kainino0x:
I prefer "always unsafe" to avoid tempting too much questioning of when it's safe. That said, am I remembering correctly that it's never really unsafe, it's just that it can cause a self-deadlock if it tries to take a lock that's already held on the same thread?

Also, for GetMappedRange maybe we could specifically document that it's safe to call in any callback (or at least in BufferMap and OnSubmittedWorkDone). That would require the implementation to guarantee either of the following:

  • said callbacks won't called spontaneously while holding any lock that GetMappedRange needs
  • GetMappedRange doesn't take any locks (it probably doesn't need them, it just needs an atomic [wrapped around the nullable mapping base pointer])

@kainino0x kainino0x enabled auto-merge (squash) January 8, 2025 05:46
@kainino0x kainino0x merged commit fedd16c into webgpu-native:main Jan 8, 2025
5 checks passed
@kainino0x kainino0x deleted the getmappedrange-reentrant branch January 8, 2025 05:48
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