Skip to content
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

It looks possible to call the value-to-be-cached twice #60

Open
vemv opened this issue Nov 23, 2016 · 0 comments
Open

It looks possible to call the value-to-be-cached twice #60

vemv opened this issue Nov 23, 2016 · 0 comments

Comments

@vemv
Copy link

vemv commented Nov 23, 2016

Related: #45

Consider the plain ruby memoization pattern:

      def foo
        @foo ||= (...)
      end

This looks thread-unsafe, because two concurrent threads which call foo for the first time at the same time could trigger the code in (...). Only one would 'win', and everything would normally from then on, but (...) has been called twice.

If that was an expensive operation, it would have been called twice (suboptimal). If it was an operation with side-effects, we might encounter actual problems.

From my understanding of memoist.rb, this doesn't seem prevented at all.

What do you think - is there room for improvement here?

Cheers - Victor

@vemv vemv changed the title It looks possible to call the value to be cached twice It looks possible to call the value-to-be-cached twice Nov 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant