int x = 0, y = 0, z = 0;void first {
   x = x + 1;
}void second {
  y = y + 1;
  x = x + 1;
}void third {
  z = z + 1;
  y = y + 1;
  x = x + 1;
}int x = 0, y = 0, z = 0;void first {
   x = x + 1;
}void second {
  y = y + 1;
  x = x + 1;
}void third {
  z = z + 1;
  y = y + 1;
  x = x + 1;
}x == 3, y == 2, z == 1 ???int x = 0, y = 0, z = 0;void first {
  synchronized(this) {
    x = x + 1;
  }
}void second {
  synchronized(this) {
    y = y + 1;
    x = x + 1;
  }
}void third {
  synchronized(this) {
    z = z + 1;
    y = y + 1;
    x = x + 1;
  }
}x == 3, y == 2, z == 1 !txn_int x = 0, y = 0, z = 0;void first {
   atomic {
     x = x + 1;
   }
}void second {
  atomic {
    y = y + 1;
    x = x + 1;
  }
}void third {
  atomic {
    z = z + 1;
    y = y + 1;
    x = x + 1;
  }
}x == 3, y == 2, z == 1 !!!class Account {
  int balance;
  synchronized void withdraw(int n) {
    balance = balance - n; 
  }
  void deposit(int n) {
    withdraw(-n);
  }
}
class Transfer  {
  void transfer(Account from, Account to, int amount) {
    from.withdraw(amount);
    to.deposit(amount);
  }
}class Account {
  int balance;
  synchronized void withdraw(int n) {
    balance = balance - n; 
  }
  void deposit(int n) {
    withdraw(-n);
  }
}
class Transfer  {
  void transfer(Account from, Account to, int amount) {
    synchronized(from) {
      synchronized(to) {
        from.withdraw(amount);
        to.deposit(amount);
      }
    }
  }
}class Account {
  txn_int balance;
  void withdraw(int n) {
    atomic {
      balance = balance - n;
    }
  }
  void deposit(int n) {
    withdraw(-n);
  }
}
class Transfer  {
  void transfer(Account from, Account to, int amount) {
    atomic {
      from.withdraw(amount);
      to.deposit(amount);
    }
  }
}void second {
  atomic {
    y = y + 1;
    x = x + 1;
  }
}Handle/Proxy
Memory
void third {
  atomic {
    z = z + 1;
    y = y + 1;
    x = x + 1;
  } 
}void second {
  atomic {
    y = y + 1;
    x = x + 1;
  }
}x =0
y =0
y =1
x =1
Memory
Write-set
read y
read x
Read-set
public class Container<T> {
  public enum TYPE { RECOVERABLE, PERSISTENT };
  public enum MODEL { SHARED, EXCLUSIVE };
  public Container ();
  public synchronized T create (T member);
  public static final Container<?>
          getContainer (Object proxy);
}
@Transactional
public interface StockLevel {
  int get () throws Exception;
  void set (int value) throws Exception;
  void decr (int value) throws Exception;
}
Container<StockLevel> container = new Container<>();
StockLevelImpl stock = new StockLevelImpl();
StockLevel stockWrapped = container.create(stock);
// update the STM object inside a transaction
// or use annotations to define transaction boundaries
AtomicAction a = new AtomicAction();
a.begin();
stockWrapped.set(1234);
a.commit();
// Implementations of interface
// are container managed
@Transactional
// Container will create
// a new transaction for each method
@Nested & @NestedTopLevel
@Optimistic & @Pessimistic
@ReadLock & @WriteLock
@State & @NotState
@TransactionFree