[concurrency-interest] Lock free caches

Holger Hoffstätte holger at wizards.de
Wed Apr 11 13:21:16 EDT 2007


Mike Quilleash wrote:
>         Map< K, V > localMap = map;
>  
>         if ( localMap.containsKey( input ) )
>             return localMap.get( input );

You could still shave off the redundant lookup here, no?

In ConcurrentMemoizer:
>         value = doCompute( input );
>         map.put( input, value );
>  
>         return value;

  value = doCompute(input);
  concurrentValue = map.putIfAbsent(input, value);

  // flip refs on conflict
  if (concurrentValue != null)
  {
      value = concurrentValue;
  }

  return value;

So you'd actually use the ConcurrentMap interface.

-h


More information about the Concurrency-interest mailing list