Hacker News new | ask | show | jobs
by cjhanks 3585 days ago
One of two (or both) things would need to be changed for it to be generally useful:

- The return value should be a WeakPtr, not a bool and a reference. This allows for data to not be duplicated by all of the different `getter` threads. A WeakPtr<Type> is kind of C++'s equivalent of a Maybe<Type>.

- The getter function also need to be passed a functor capable of generating the object, which then creates a `named lock` that /only/ other threads requesting that key. This duplicates multiple logical copies of the same item from being created (this is important when the creation is expensive, presumably the core reason for using an LRU cache).

edit: formatting, I am not familiar with HN syntax.