Code example for AtomicReferenceFieldUpdater

Methods: compareAndSet

0
                int nsz = pos * 2;
                if (nsz > marklimit)
                    nsz = marklimit;
                byte nbuf[] = new byte[nsz];
                System.arraycopy(buffer, 0, nbuf, 0, pos);
                if (!bufUpdater.compareAndSet(this, buffer, nbuf))
                { 
                    // Can't replace buf if there was an async close. 
                    // Note: This would need to be changed if fill() 
                    // is ever made accessible to multiple threads. 
                    // But for now, the only way CAS can fail is via close. 
                    // assert buf == null; 
                    throw new IOException("Stream closed");
                } 
                buffer = nbuf;
            } 
        count = pos;
        int n = getInIfOpen().read(buffer, pos, buffer.length - pos);
        if (n > 0)
            count = n + pos;
    }