-
Notifications
You must be signed in to change notification settings - Fork 328
Support concurrent async writes to mutable data in Rust #1917
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
Comments
Firstly, I guess it is related to #1883.
I think so.
Yes that's also a possibility. I need to think a bit more about this. The single-thread proposal in #1883 may not work in this specific issue, because we are using Do you have any brainstorms about solving this? |
Linking #1910 (comment) since it's closely related. With the caveat that I'm about 48hrs into learning about this, at a high level my brainstorm would be that a developer needs to choose a concurrency strategy for each part of their data and stick to it holistically across a whole application for that data. Several different strategies could work but they have different constraints and tradeoffs. FRB could in theory support more than one strategy, but each project would have to stick to a single strategy for each piece of data. Here's a few strategies that should work: An unwrapped data strategy:
A generated lock strategy:
A hand-coded synchronization strategy:
|
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new issue. |
Describe the bug
It's hard to write correct code with
&mut
that mutates data that is stored in the Rust layer.Steps to reproduce
This repro causes #1910 but it also creates PanicExceptions: https://github.com/aran/frb-exc-repro/blob/mut/lib/main.dart
Logs
Expected behavior
No response
Generated binding code
No response
OS
No response
Version of
flutter_rust_bridge_codegen
No response
Flutter info
No response
Version of
clang++
No response
Additional context
One hypothesis is that one of the levels of async might be acquiring the FRB-generated RwLock then yielding while still holding it. This allows runtime errors. Another theory is that in the Rust thread pool, multiple Dart-level Futures could be running simultaneously, and if there are both readers and writers of some variable that was
&mut
and&
, they can collide.The programming model of
&mut
and&
is often going to be a leaky abstraction w.r.t. theRwLock
model.The text was updated successfully, but these errors were encountered: