-
Notifications
You must be signed in to change notification settings - Fork 0
Non-repeating design for atomic lazy #17
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
base: lazy-repeating-atomic
Are you sure you want to change the base?
Non-repeating design for atomic lazy #17
Conversation
|
I have mixed feelings about this. It asks users to explain how they want to wait on an ongoing computation, and then how they want to signal that a computation is done to re-activate the waiters. I think that this is a reasonable interface for an agnostic approach to blocking. This is a positive point about your PR, but it also means that your implementation is trying to solve a different problem from mine and should be considered independently : we could have a separate I am also not sure that your proposal is better than other proposed designs to explain how to wait, for example the one proposed by Leo on Discuss. Your proposal should be contrasted and compared to those alternative proposals for an agnostic-blocking approach, rather than just to mine, to make an informed decision. I'm not sure that your API is quite right. For example there is no way to have a function I have mixed feelings when contrasting our two examples with mutexes:
I'm confident that my recipe can be ported by users to other concurrency libraries in a simple way, by replacing mutexes with another, scheduler-specific exclusion mechanism. Yours can also be ported in a simple way, maybe even simpler, for libraries that have clear and pleasant waiting-oriented data structures, but its implementation using locks is meh. (Less painful to use than pthreads condition variables.) Regarding a non-blocking variant of In summary, my conclusion: this is a proposal for an alternative Lazy.Atomic_blocking module which has merit, but should be understood as a proposal to do scheduler-agnostic blocking and be compared with other proposals in that space. You could/should open your own upstream PR. |
|
(Nitpick: I find the name "race_behaviour" rather uncomfortable due to the other meaning of "race" it brings to mind. I would recommend calling this "blocking_behaviour" instead or "sync_ops" or whatever.) |
My point when submitting this PR was to show that repeating was not necessary to provide concurrency-safe lazy thunks. You might also notice that the I actually wish we could have discussed that in person (or by visio); it's hard to properly discuss this using only Github comments.
Yes, I agree. I left it as it is because I wasn't really planning to push this through, but if I had to actually make a PR upstream I would change it. |
|
I'm happy to let this topic wait for our next in-person conversation. Thanks! |
Here is a proposal for achieving the goals of concurrency-safe lazy values while still providing a guarantee that the function will be called at most once.
The third example from the documentation would look like this:
I also included a non-blocking version of
force(which returns an option), as I think it could be useful.