-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Add library for "Shared state is just a mode of use of concurrency" #3117
Comments
I am not sure how useful such a thing would be in the standard library. My big concern is the matter of lifetime—how do you signal when the thing is freed? This seems to (in the general case) require a GC or be prone to malloc/free-like dangling pointers. I'd kind of rather that people think about their task design in a more holistic sense where these answers will hopefully fall out of the application. |
@nikomatsakis So, pipes let the receiver know when the other endpoint is dropped. My thought was for the server task to internally keep a list of active endpoints -- whenever one closes, it removes it from the list, and when the list becomes empty, the server exits entirely. Basically this would achieve refcounting isomorphic to how exclusive arcs do it today. The weaken_task bit mentioned above "solves" the circular reference problem - I mean, repeatedly generating circular references and dropping them would still result in memory blowup, but at least the runtime knows how to clean them up when the whole program exits (so there's not actually a "leak" in the assertion-failure-runtime-crash sense of the word). I dunno, I've always kind of taken it for granted that people will want shared mutable state. |
I see. I knew that you and @eholk were discussing this so I should have phrased it more like a question. Interesting: the failure more with weak tasks is certainly not ideal. |
We talked about this and decided it wasn't wise to do. Whether or not the library forbids cycles, |
avoid confusing loop in catch_panic test Fixes rust-lang/miri#3115
Dependency upgrade resulting from `cargo update`.
The idea is that you can implement shared-state-between-tasks by having some sort of "shared state management task", and using message-passing to access/modify the state by communicating over a protocol.
This will replace exclusive ARCs as the user-facing 'mutable shared state' primitive. We don't want to expose exclusives because there's no way to avoid potential for memory leaks with circular references. (If there is such a way... let me know!)
Proposed interface/design, something like:
Some comments:
const
restriction - handles are sendable but mutable, so the state library will refuse to manage handles recursively. Users can put singly-linked data structures in these using ~-pointers, but still can not create circularly-linked data structures.The text was updated successfully, but these errors were encountered: