package edu.nyu.cs9053.concurrency.chapter14.atomicity;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * User: blangel
 * Date: 7/26/14
 * Time: 4:27 PM
 */
public class ThreadSafeWithLock {

    private final AtomicInteger bounded;

    public ThreadSafeWithLock(int value) {
        this.bounded = new AtomicInteger(value);
    }

    public synchronized void addUpTo100(int delta) {
        if ((bounded.get() + delta) < 100) {
            bounded.addAndGet(delta);
        }
    }
}
