+/EE360P

distributed systems

git clone https://git.julia.blue/+/EE360P

vijaygarg1add stack and queuecccc41d

master
528 B16 linesraw
1import java.util.concurrent.atomic.*;
2class MyAtomicInteger extends  AtomicInteger {
3    public MyAtomicInteger(int val) { super(val);}
4    public int myAddAndGet(int delta) {
5        for (;;) {
6            int current = get();
7            int next = current + delta;
8            if (compareAndSet(current, next))
9                return next;
10        }
11    }
12    public static void main(String[] args) throws Exception {
13        MyAtomicInteger x = new MyAtomicInteger(10);
14        System.out.println(x.myAddAndGet(5));
15    }
16}