-
Notifications
You must be signed in to change notification settings - Fork 328
Should OpaqueObject use read/write instead of try_read/try_write ? #1883
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
Good question! IIRC it is currently try_read/try_write partially because to avoid deadlock problems. As you know, suppose we have 2 opaque objects, it is really easy to create deadlock, especially under the scenarios you mentioned. Brainstorms:
|
I think maybe deadlock is ok because pure rust also cannot prevent it. (Best practices should be documented) If there is some deadlock detection, then I think it's perfect Ok. If we model application state as opaque object, the current multi-thread model locks everywhere to prevent data race and does not benefit much from it. Maybe it's better to multi-threading stateless calls and event-loop stateful(opaque object) calls. |
I will reconsider it a bit later and see what to implement! |
You can't get deadlocks in simple rust code that just uses ownership, &mut ref / &ref. You also can't get deadlocks in plain Flutter. Given the focus on safety, I would advocate that any changes here would aim to avoid introducing runtime errors like deadlocks or runtime borrow failures unless the developer explicitly opts in to using a less safe feature set. $0.02, I think it's ok for a developer to risk a deadlock if they call lock.read() or lock.write() in their own code. I don't think it's ok for the framework to introduce a behind-the-scenes lock if its usage is not 100% safe. |
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. |
Often rust code is called in a flutter event callback, it's common that user click another buttons while processing.
It is quite easy to call methods of the same opaque object a second time, and rust just panick.
Surely we can restrict calls at flutter side, but it's fragile.
Usually it's ok waiting previous call to complete, and read/write is just what users want.
So I think use read / write is better than currently try_read / try_write.
Of course it's even better if we can config this.
What do you think ? Thanks
The text was updated successfully, but these errors were encountered: