Advertisement
frasl

Untitled

Mar 10th, 2019
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. class BankAccount {
  2.   int balance_;
  3. public:
  4.      void Deposit(int amount, StrictLock<BankAccount>&) {
  5.     // Externally locked
  6.     balance_ += amount;
  7.   }
  8.   void Deposit(int amount) {
  9.     Lock guard(*this); // Internally locked
  10.     Deposit(amount, guard);
  11.   }
  12.     void Withdraw(int amount, StrictLock<BankAccount>&) {
  13.     // Externally locked
  14.     balance_ -= amount;
  15.   }
  16.   void Withdraw(int amount) {
  17.     Lock guard(*this); // Internally locked
  18.     Withdraw(amount, guard);
  19.   }
  20. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement