예제 #1
0
파일: Tests.cs 프로젝트: srstrong/NDC-CHESS
        public void TwoConcurrentTransfersOnTheSameAccountsIsValid_CHESS()
        {
            var a = new Account(1);
            var b = new Account(2);
            var bank = new Bank();

            Parallel.Invoke(() => bank.Transfer(a, b, 100),
                () => bank.Transfer(b, a, 100));
        }
예제 #2
0
        public void TransferTo(Account other, double amount)
        {
            //Account a = (other.Id > this.Id) ? this : other;
            //Account b = (other.Id <= this.Id) ? this : other;

            lock (this)
            {
                Spin();
                lock (other)
                {
                    Spin();
                    this.Balance -= amount;
                    other.Balance += amount;
                }
            }
        }