You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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
Related: #45
Consider the plain ruby memoization pattern:
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
The text was updated successfully, but these errors were encountered: