[concurrency-interest] CHM putIfAbsent

Nabib El-Rahman nabiber at gmail.com
Wed May 26 03:37:03 EDT 2010


Hello,

I don't know if this exist, But I need someway of executing an set of
statements atomically under the lock of the appropriate CHM segment.
That way I keep the correctness of the synchronization while still getting
the concurrency benefit of CHM.

Something like this:

 public V putIfAbsent(K key, Callable callable) {
    if (value == null) throw new NullPointerException();
    int hash = hash(key.hashCode());
    Segment seg = segmentFor(hash);
    //grab segment, and then call a function under a segment lock
    seg.put(key, hash, callable, true);
  }

Segment {

   public(K key, int hash, Callable callable, boolean checkIfAbsent) {
     // if absent, then..

     lock();

    try {

     //method executed under segment lock, return value put into map..
      put(key, hash, callable.execute());
   } finally {

     unlock();

  }
}


Thanks

-Nabib
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20100526/6c7c7f1d/attachment.html>


More information about the Concurrency-interest mailing list