You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Ohad Shacham <oh...@cs.tau.ac.il> on 2010/06/15 16:26:49 UTC

ConcurrentCache atomicity violation

Hi,



We are writing a tool to detect atomicity violations in usage of
ConcurrentHashMap.

We have run the tool that reported an atomicity violation in functions get
and put of class ConcurrentCache.

The following code shows the put function of the ConcurrentCache:



    public void put(K k, V v) {

        if (this.eden.size() >= size) {

            this.longterm.putAll(this.eden);

            this.eden.clear();

        }

        this.eden.put(k, v);

    }



In this code the tool discovered a scenario that a (k,v) pair is added to
eden and a clear operation deletes this pair without copying it to the
longterm hash.

We would be happy if you can let us know if this is a bug or this is a valid
behavior of the cache.

Another problem is that longterm is a WeakHashMap which is not a thread safe
implementation.



Thanks,

Ohad

ConcurrentCache atomicity violation

Posted by Ohad Shacham <oh...@gmail.com>.
Hi,



We are writing a tool to detect atomicity violations in usage of
ConcurrentHashMap.

We have run the tool that reported an atomicity violation in functions get
and put of class ConcurrentCache.

The following code shows the put function of the ConcurrentCache:



    public void put(K k, V v) {

        if (this.eden.size() >= size) {

            this.longterm.putAll(this.eden);

            this.eden.clear();

        }

        this.eden.put(k, v);

    }



In this code the tool discovered a scenario that a (k,v) pair is added to
eden and a clear operation deletes this pair without copying it to the
longterm hash.

We would be happy if you could let us know whether this is a bug or whether
it is a valid behavior of the cache.

Another problem that we have found is that longterm is a WeakHashMap which
is not a thread safe implementation and there exists a trace that many
threads run this.longterm.putAll(this.eden); concurrently.



Thanks,

Ohad