/** * CSE 374 18sp example * A simple bank account class that we'll use to demonstrate proper * synchronization. */ #ifndef BANKACCOUNT_H #define BANKACCOUNT_H #include #include class BankAccount { public: BankAccount(); void deposit(double amount); void withdraw(double amount); double getBalance(); void setBalance(double amount); void transferTo(double amount, BankAccount& other); private: // This function should only be called once the mutex is already locked. void setBalanceWithLock(double amount); const int accountId_; // This mutex protects access to the balance_. std::mutex m_; double balance_; // The count is atomic so that when we get a new id, we don't have any data // races. static std::atomic accountCount_; }; #endif