public static void main(String args[]) throws Exception{
        SpinLockMutex slm = new SpinLockMutex();
        Mutex m = new Mutex();
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                m.acquireLock();
                slm.changeBuffer("a" + i);
                m.releaseLock();
            }
        });

        Thread t2 = new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                m.acquireLock();
                slm.changeBuffer("b" + i);
                m.releaseLock();
            }
        });

        t1.start();
        t2.start();
        try {
            t1.join();
            t2.join();
        } catch (InterruptedException e) {
            throw e;
        }
        System.out.println(slm.getBuffer());
    }
Val is stored somewhere. If oldVal is same as val
then you change val to newVal and return oldVal
Otherwise you do nothing but return val
@param oldValue
@param newValue
@return
src/com/interview/multithreaded/SpinLockMutex.java