reading needs to synchronize as well
authorJaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 10:04:34 +0200
changeset 204bd5089d23771
parent 203 0e46110eebc1
child 205 6ad6f4162691
reading needs to synchronize as well
samples/reentrant/src/org/apidesign/reentrant/CriticalSectionReentrantImmutable.java
     1.1 --- a/samples/reentrant/src/org/apidesign/reentrant/CriticalSectionReentrantImmutable.java	Sat Jun 14 10:04:19 2008 +0200
     1.2 +++ b/samples/reentrant/src/org/apidesign/reentrant/CriticalSectionReentrantImmutable.java	Sat Jun 14 10:04:34 2008 +0200
     1.3 @@ -13,7 +13,10 @@
     1.4      // BEGIN: reentrant.merge.immutable
     1.5      public int sumBigger(Collection<T> args) {
     1.6          for (;;) {
     1.7 -            ImmutableData<T> previous = this.data;
     1.8 +            ImmutableData<T> previous;
     1.9 +            synchronized (this) {
    1.10 +                previous = this.data;
    1.11 +            }
    1.12              int[] ret = { 0 };
    1.13              ImmutableData<T> now = doCriticalSection(args, previous, ret);
    1.14