groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Remi Forax <fo...@univ-mlv.fr>
Subject Re: Groovy category throwing MissingMethodException and MissingPropertyException when using multiple threads
Date Thu, 29 Oct 2015 20:00:55 GMT
Hi Jochen,

line 75:
  atomicCategoryUsageCounter.incrementAndGet();
  categoriesInUse = atomicCategoryUsageCounter.get();

you increment the counter and then get the value, but another thread can change the counter
in between,
in that case you end up with the wrong value.
The fix is to ask for the value of the counter at the same time,
   categoriesInUse = atomicCategoryUsageCounter.incrementAndGet();
  
line 99:
  atomicCategoryUsageCounter.getAndDecrement();
  categoriesInUse = atomicCategoryUsageCounter.get();

same issue, the fix is
  categoriesInUse = atomicCategoryUsageCounter.decrementAndGet();

Note: I've replaced getAndDecrement by decrementAndGet to keep the same semantics.

cheers,
Rémi

----- Mail original -----
> De: "Jochen Theodorou" <blackdrag@gmx.org>
> À: dev@groovy.incubator.apache.org, users@groovy.incubator.apache.org
> Envoyé: Jeudi 29 Octobre 2015 20:52:26
> Objet: Re: Groovy category throwing MissingMethodException and MissingPropertyException
when using multiple threads
> 
> On 29.10.2015 11:48, Suderman Keith wrote:
> > There are (at least) two race conditions in GroovyCategorySupport.java
> > that would explain the intermittent and hard to reproduce bugs.
> >
> > I was hoping to submit this as my first official pull request to the
> > Groovy project, but gradle has different ideas…
> >
> > However, the offending code is in on lines 75-76 and 99-100 where
> > atomicCategoryUsageCounter is used non-atomically. If no one beats me to
> > it I will submit a PR once I puzzle out why ./gradlew test is failing
> > for me.
> 
> Can you explain the non-atomic usage and why it leads to a problem here?
> 
> bye blackdrag
> 

Mime
View raw message