[concurrency-interest] StampedLock

Dr Heinz M. Kabutz heinz at javaspecialists.eu
Mon Oct 15 06:51:06 EDT 2012


A few more minor gotchas about the Point example.

We should probably make the class Point and its methods public.

Then, in distanceFromOriginV2(), the local variables currentX and 
currentY need to be initialized to zero, otherwise the compiler 
complains.  So distanceFromOriginV2() should probably be:

   public double distanceFromOriginV2() { // combines code paths
     for (long stamp = sl.tryOptimisticRead(); ; stamp = sl.readLock()) {
       double currentX=0, currentY=0;
       try {
         currentX = x;
         currentY = y;
       } finally {
         if (sl.tryConvertToOptimisticRead(stamp) != 0L) // unlock or 
validate
           return Math.sqrt(currentX * currentX + currentY * currentY);
       }
     }
   }

Lastly, in moveIfAtOrigin, we have another typo.  It should be

         long ws = sl.tryConvertToWriteLock(stamp);

instead of

         long ws = tryConvertToWriteLock(stamp);

These are all very minor issues.

Regards

Heinz
-- 
Dr Heinz M. Kabutz (PhD CompSci)
Author of "The Java(tm) Specialists' Newsletter"
Sun Java Champion
IEEE Certified Software Development Professional
http://www.javaspecialists.eu
Tel: +30 69 75 595 262
Skype: kabutz 



On 10/13/12 2:12 AM, Doug Lea wrote:
> On 10/12/12 16:17, Zhong Yu wrote:
>> The example calls optimisticRead()
>>
>>     double distanceFromOriginV2() { // combines code paths
>>       for (long stamp = sl.optimisticRead(); ; stamp = sl.readLock()) {
>>
>
> Thanks! This should be tryOptimisticRead(). Fixed.
>
> -Doug
>
>>>
>>> http://gee.cs.oswego.edu/dl/jsr166/dist/jsr166edocs/jsr166e/StampedLock.html 
>>>
>>> And see the usual links from
>>>    http://gee.cs.oswego.edu/dl/concurrency-interest/index.html
>>> for jsr166e jars and sources.
>>>
>>> Reports about usage experiences would be very welcome!
>
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>


More information about the Concurrency-interest mailing list