-
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
Added method to unpoison poisoned RWARCs #7392
Conversation
This is mostly a prototype for future changes. I assume more complicated methods like unpoison_with_condvar may need to be added but the whole complicated mess of varying types of writes, and reads need to be refactored, and turned into a cleaner, and better interface anyways. Personally, I need this operation to implement functions for the library of concurrent data structures I am working on but this operation may be of interest to others. A rustic style for cleaning up the interface is unclear to me at the moment but a possible example in Haskell might be to use a monad, and have write simply be a consequence of the logically more primitive read, and unpoison operations. This monadic approach in Haskell might look like the following: atomicIncrement var = atomically $ do x <- read var var $= x + 1
cc @bblum |
I'm not sure having an When I first wrote poisoning, I thought of it as making an RWARC implicitly be sort of a back-channel for linked failure propagation. I could imagine a use case that wanted to avoid poisoning, and at the time figured the best way would actually be to offer a The thing I think this function wants to be, which could coexist with the above, is an access function that provides optional data instead of failing automatically:
The current access functions could, of course, be implemented using those and |
Also, implementing write as a nonprimitive on top of read and unpoison would break the atomicity provided by the write-locked rwlock. |
@bblum I think having it be not higher order would be cleaner but I heard that having a thunk can be optimized better than just regular parameter passing. Having a thunk is ugly though so I'll make it just be a normal parameter. I don't think doing a micro-optimization in this case is worth it. Besides now the poison on fail stuff can be removed. I feel silly that I missed the race condition with spawn_unsupervised. Okay! The zeroing of destroyed data makes much more sense to me now after reading your comment on the failure check stuff mistake. I don't think I'll make that kind of mistake again. I don't follow what you mean by saying that any task that wants to do this will need to make sure their unpoison attempt was successful. This sort of check would be nicer in a monadic style though (although as mentioned above I really don't know how to make that style rustic.) For example,
|
Personally, I feel that a RWARC::new_without_poisoning is an ugly approach because it introduces polymorphism of behaviour in a bad, and inelegant way. A better approach might be to make RWARC an interface that could be tightened, or relaxed as needed. For example, a naively written function that took a RWARC could simply take a CheckedRWARC value, and a function that was written, and confirmed not to poison a value could be polymorphic over any value that implemented the RWARC interface. Though this approach would be better, I still think it's silly. Why not go with a simpler approach? |
Fix `any()` not taking reference in `search_is_some` lint `find` gives reference to the item, but `any` does not, so suggestion is broken in some specific cases. Fixes: rust-lang#7392 changelog: [`search_is_some`] Fix suggestion for `any()` not taking item by reference
This is mostly a prototype for future changes. I assume more
complicated methods like unpoison_with_condvar may need to be added
but the whole complicated mess of varying types of writes, and reads
need to be refactored, and turned into a cleaner, and better interface
anyways. Personally, I need this operation to implement functions for
the library of concurrent data structures I am working on but this
operation may be of interest to others.
A rustic style for cleaning up the interface is unclear to me at the
moment but a possible example in Haskell might be to use a monad, and
have write simply be a consequence of the logically more primitive
read, and unpoison operations. This monadic approach in Haskell might
look like the following: